[mdlug] UNIX tips: Learn 10 good UNIX usage habits

Raymond McLaughlin driveray at ameritech.net
Sun Mar 9 17:23:43 EDT 2008


Aaron Kulkis wrote:
>    Level: Intermediate
> 
> Michael Stutz (stutz at dsl.org), Author, Consultant
>   12 Dec 2006
> 
> Adopt 10 good habits that improve your UNIX command line efficiency 
<Snip>
<http://www.ibm.com/developerworks/aix/library/au-badunixhabits.html?ca=dgr-lnxw06tenunixtips&S_TACT=105AGX59&S_CMP=GR>

This looks pretty good, but isn't quite as clear as it could be. For
instance, after introducing: the "&&" and "||"  control operators we are
given this, without explanation

  Listing 7. A combined example of good habit #3: Combining commands
with control operators
  ~ $ cd tmp/a/b/c || mkdir -p tmp/a/b/c && tar xvf -C tmp/a/b/c
~/archive.tar

So does execution stop if the cd command, or just skip the mkdir command
and move on to the tar command? I would guess the later is what would be
desired, but a sentence stating so would remove such guess work.

Also, the next listing doesn't work as advertised, at least not in BASH
on my system (OpenSuSE 10.3).

  Listing 8. Example of good habit #4: Quoting (and not quoting) a variable

  ~ $ ls tmp/
  a b
  ~ $ VAR="tmp/*"
  ~ $ echo $VAR
  tmp/a tmp/b
  ~ $ echo "$VAR"
  tmp/*
  ~ $ echo $VARa

  ~ $ echo "$VARa"

  ~ $ echo "${VAR}a"
  tmp/*a
  ~ $ echo ${VAR}a
  tmp/a

This all works the same for me, except that last one. On my system the
last two do the same thing:

  pts/1 $ echo "{$VAR}a"
  {tmp/*}a
  pts/1 $ echo {$VAR}a
  {tmp/*}a
  pts/1 $

I don't know if the author used a different shell, or has different
globbing options set, but I don't see just how that last one is even
supposed to work.

This article seems worth the read, but seems to need a little work.

Regards
Raymond McLaughlin




More information about the mdlug mailing list