LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Ubuntu: commands with ' ' are failing (https://www.linuxquestions.org/questions/linux-newbie-8/ubuntu-commands-with-are-failing-894730/)

greenpool 07-31-2011 03:14 AM

Ubuntu: commands with ' ' are failing
 
hi,

the following appears to be failing. i hope someone can tell me why..

so i'm trying to create a file with the current date as the prefix in the following way (following instructions from a tutorial):

Code:

touch 'date +%F'.log
its creating the file as:

date +%F.log

instead of 2011-07-31.log

i also tried the following:

Code:

var='expr 1 + 2'
echo $var

now i thought it should display the result as 3 but instead its printing the string:

expr 1 + 2


what am i getting wrong/missing/failing to understand?

thanks!

Wim Sturkenboom 07-31-2011 03:33 AM

Use backticks instead of ticks
Code:

fortyfourgalena@desktop-01:~$ touch `date +%F`.log
fortyfourgalena@desktop-01:~$ ls 2011*
2011-07-31.log
fortyfourgalena@desktop-01:~$


chrism01 07-31-2011 07:05 PM

Or try $(); easier to read
Code:

touch $(date +%F).log
2011-08-01.log


corp769 07-31-2011 07:08 PM

Quote:

Originally Posted by chrism01 (Post 4430222)
Or try $(); easier to read
Code:

touch $(date +%F).log
2011-08-01.log


Normally, that would depend on the user. Me personally, I use both, but mainly I use backticks.

chrism01 07-31-2011 07:27 PM

Yeah, I'm old school myself, but it is easier to read, especially across environments. I actually tested that on the Solaris system in front of me, just to see if it worked there.

corp769 07-31-2011 07:33 PM

Quote:

Originally Posted by chrism01 (Post 4430240)
Yeah, I'm old school myself, but it is easier to read, especially across environments. I actually tested that on the Solaris system in front of me, just to see if it worked there.

I could have told you that :p

And honestly, I don't think I will be ever considered "new school....." ;)


All times are GMT -5. The time now is 03:57 PM.