cc: [email protected]
Subject: Re: [ast-users] [ ] vs [[ ]] usage differences
--------
> I was wondering if somebody could explain what is the difference in use of
> the a
> bove within 'if' statement.
> Is one superseds the other so I can use just one without ever considering the
> ot
> her.
>
> Sample:
> If [ -d somedir ];then
> ...
>
> Thank you, gene.
>
In this case there is no difference, but
[[ ... ]]
is part of the shell grammar, whereas
[ ... ]
is a regular command equivalent to test ...
This means that ... does all the expansions which can lead to unexpected
results.
Since [[ ... ]] doesn't do file name generation, shell patterns can be
recongnized without being treated as file matches.
For example
[[ $x == *foo* ]]
will compare the value of x with the pattern *foo* which matches any string
containing foo, wherease
[ $x = *foo* ]
will match the value of x with a file name matching *foo* in the current
directory. If there is more than one match, this will generate an error.
If there is no match, the the value of x will be matched against the
string "*foo*"
David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users