[Linux-disciples] Equivalent bash syntaxes

Chung-chieh Shan ccshan at post.harvard.edu
Wed Jul 30 22:14:03 EDT 2008


On 2008-07-21T11:31:55-0400, Stephen R Laniel wrote:
> Is there any reason to prefer any of the
> following three forms to either of the
> other two?
> 
> - test expression && action
> 
> - if test expression; then
>       action
>   fi
> 
> - if [ expression ]; then
>       action
>   fi

"test" and "[ ... ]" are synonymous.

On 2008-07-21T11:37:55-0400, Jamie Forrest wrote:
> Does #1 allow for multiple actions?

On 2008-07-21T11:44:06-0400, Stephen R Laniel wrote:
> (11:43) slaniel at dops-slani2:~$ test -e /home/slaniel && (echo foo; echo bar)
> foo
> bar

Because parentheses spawn a subshell, it's not quite the same as "if":

    $ test -e /home/ccshan && (foo=this; bar=that)
    $ echo $foo

    $ echo $bar

    $ if test -e /home/ccshan; then
    >   foo=this
    >   bar=that
    > fi
    $ echo $foo
    this
    $ echo $bar
    that

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
http://www.whatdotheyknow.com/ http://www.undemocracy.com/
http://www.digistan.org/hague-declaration
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20080730/2b2e9350/attachment.pgp 


More information about the Linux-disciples mailing list