Linked by Eugenia Loli-Queru on Thu 8th Feb 2007 21:16 UTC
Thread beginning with comment 210682
To view parent comment, click here.
To read all comments associated with this story, please click here.
To view parent comment, click here.
To read all comments associated with this story, please click here.
I think he wanted to set the variable mydir to the output of the pwd command, which is what that statement does as written. However, a better way to write this kind of operation (in any Bourne-like shell) is:
mydir=$(pwd)
This is the preferred syntax for assigning the output of a shell command to a variable. One of the reasons is that backticks cause confusion. Or, in this particular case, this would be more efficient:
mydir=$PWD
$PWD is an environment variable available in every UNIX-like shell I've ever encountered.







Member since:
2005-07-22
Remember, the meaning of GNU...
Actually, there have been variants in shell processing in Unix and Linux systems for years. How many shells are there in a standard Linux Distro? Each of these have little quirks of their own. Some handle spaces in directory names better than others. etc etc etc.
I have used the construct you have used in your example in Unix for example
mydir=`pwd`
Overall, these little differences are small and IMHO pretty insignificant.
I have a subset of shell commands which work pretty well on virtually any shell in Unix or Linux (apart from older AIX versions...) which enables me to write pretty portable scripts without too much trepidation.
Any clearly written text on shell programming is very worthwhile IMHO.