LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2006, 10:40 AM   #1
RonV
LQ Newbie
 
Registered: Apr 2005
Location: Hoffman Estates, IL
Distribution: Debian Sarge
Posts: 9

Rep: Reputation: 0
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?

Thanks
 
Old 06-04-2006, 10:55 AM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
You need to use the backtick (`), not the single quote ('). Still, the first form $() is preferred.
 
Old 06-04-2006, 01:11 PM   #3
RonV
LQ Newbie
 
Registered: Apr 2005
Location: Hoffman Estates, IL
Distribution: Debian Sarge
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks, the publisher must have goofed on the book....everything is in courier and shows the apostrophe not the back tic.....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash variable substitution daYz Programming 3 04-14-2006 02:16 PM
Bash Process Substitution joshholt Programming 4 10-11-2005 04:15 AM
bash assignments of commands substitution p0rtius Programming 6 07-03-2005 07:41 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 01:20 AM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 06:34 AM


All times are GMT -5. The time now is 06:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration