-   Linux - Newbie (
-   -   Varible substitution in Bash script (

RonV 06-04-2006 10:40 AM

Varible substitution in Bash script
I have been doing shell type scripting for years in VMS and Windows. I am trying to do some basic scripting in Bash that substitutes values in variables. In the book I am using it has two examples:

mydate=$( date +%Y-%m-%d )
mydate2='date +%Y-%m-%d'
echo ${mydate}
echo ${mydate2}

These should both return the same value: 2006-06-04

But this is the output I get:

2006-06-04 - This is from mydate
date +%Y-%m-%d - This is from mydate2

It was my uderstanding that single quoted commands should also assign to the variable. Am I doing something wrong?


uselpa 06-04-2006 10:55 AM

You need to use the backtick (`), not the single quote ('). Still, the first form $() is preferred.

RonV 06-04-2006 01:11 PM

Thanks, the publisher must have goofed :cry: on the book....everything is in courier and shows the apostrophe not the back tic.....

All times are GMT -5. The time now is 11:07 AM.