about quote in command

Mikkel L. Ellertson mikkel at infinity-ltd.com
Thu Dec 6 19:05:26 UTC 2007


adrian kok wrote:
> Hi all
> 
> how can I make the quote correct?
> 
> `tail -n 1 `date "+%Y-%m-%d-%H"`.txt`
> 
> `date "+%Y-%m-%d-%H"`.txt is file
> 
> thank you
> 
The problem is that the first ` matches the one at the start of the
date command, and not the one after .txt, so you have to use a
different method of running a command. You can substitute $() for
one pair of back quotes.

$(tail -n 1 `date "+%Y-%m-%d-%H"`.txt)
or
`tail -n 1 $(date "+%Y-%m-%d-%H").txt`

Another way to do it, especially if you need the name in more then
one place, is to do something like this:

file_name=$(date "+%Y-%m-%d-%H").txt

tail -n 1 $file_name

Mikkel
-- 

  Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20071206/407b5f52/attachment-0001.sig>


More information about the fedora-list mailing list