Linked by Eugenia Loli-Queru on Thu 8th Feb 2007 21:16 UTC
General Unix UNIX has a dialect all its own and you will find with the UNIX command-line, there are many ways to skin a cat. Martin Streicher, Editor-in-Chief, Linux Magazine, shares his extensive knowledge and experience with command-line combinations to help you expand your mastery of the UNIX language and in the command-line in particular.
Thread beginning with comment 210682
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Details
by shotsman on Thu 8th Feb 2007 22:16 UTC in reply to "Details"
shotsman
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.

Reply Parent Bookmark Score: 1

RE[2]: Details
by archiesteel on Fri 9th Feb 2007 00:15 in reply to "RE: Details"
archiesteel Member since:
2005-07-02

mydir=`pwd`

Careful, you have backquotes instead of apostrophes there...wouldn't that simply assign the value of the current directory to mydir, instead of the actualy pwd command?

Reply Parent Bookmark Score: 3

RE[3]: Details
by butters on Fri 9th Feb 2007 01:09 in reply to "RE[2]: Details"
butters Member since:
2005-07-08

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.

Reply Parent Bookmark Score: 3