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.
This is good stuff, but there are some issues. The version of rename on my system (Mandriva 2007) doesn’t seem to take a regular expression. The man file documents it’s arguments like this:
rename from to file…
Also this won’t work:
alias mv=mv -i
You need to use quotes:
alias mv=’mv -i’
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.
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?
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.
Yes, you’re absolutely right, hence the choice of the name “mydir” for the variable. (Doh!)
I’m sorry, it’s been a long day!
Use of perl instead of sed or tr, very nice.
check my site for other CLI related tasks:
http://toya.net.pl/~vermaden/links.htm
Very interesting article (allthough for some tasks grep, sed and awk would be my choice instead of perl). And thanks for the link. It will be very useful for those few chosen who “still” use the command line.