Re: about quote in command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!

Attachment: signature.asc
Description: OpenPGP digital signature


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux