Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash scripting



--------

|  >I came accros the following construct in a bash script:
|  >
|  >if [ ! -f /path_to_file_1 -a -f /path_to_file_2 ] ; then
|  >        execute some stuff
|  >fi
|  >
|  >My question is what is the -a option?
|  
|  
|  The -a option specifies "logical AND"
|  
|  While running bash try invoking the builtin
|  "help" command (just to get a sense of what
|  bash is always standing by to help you with)
|  and then say "help [" so bash can remind
|  you that the "[" command is really just
|  an alias for the "test" command, and then
|  finally say "help test" and stand back -
|  all the possible options will go flying by,
|  including the "-a" one you inquired about...

And therin lies one of the explanations for the slowness of
shell scripts:  A test involves forking a subprocess.

This doesn't matter for most 5-line scripts, but it's  part
of  why  it's  nice to have real programming languages like
perl or tcl or python for when you want your script  to  do
something non-trivial.

(I've heard rumors that some versions of some shells do the
test  as a builtin, but I've had trouble verifying this.  I
know that the original Bourne shell  did  use  subprocesses
for  tests, and I've seen vague comments that this is still
more common than you might expect a quarter century later.)

-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org