Afficher un message
Vieux 05/11/2006, 17h42   #8
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: obtain the result of a command (success or failure) directly in a if instruction

2006-11-5, 11:00(-05), Bill Marcum:
[...]
> You don't need brackets. The left bracket itself is a command, a
> synonym for "test". (when it's called '[' it requires a ']')
>
> if ls bar 1>/dev/null 2>&1; then echo success; fi
>
> You could also write
> if [ -e bar ]; then echo success; fi


It should be noted though that the two commands above are not
equivalent if "bar" is a directory or a symbolic link whose
target we can't determine the existence.

> By the way, `ls bar 1>/dev/null 2>&1` results in an empty string, which
> evaluates as false inside [ ].

[...]

Actually, as it is not quoted, it results in no argument at all
(which is not the same thing as an empty argument) but in any
case, "[" returns false for both [ ] and [ "" ].

--
Stéphane
  Réponse avec citation
 
Page generated in 0,06708 seconds with 9 queries