Tente usar o teste -z:
if [ -z "" ] && [ -z "" ]
De man bash :
-z string
True if the length of string is zero.
Estou executando algum script que passa o argumento string e quero fazer if else declaração mostrada abaixo:
if [ != '' ] && [ != '' ]
then
do something.....
mas foi mostrado Error too many argument . Por quê?
Tente usar o teste -z:
if [ -z "" ] && [ -z "" ]
De man bash :
-z string
True if the length of string is zero.
Como isso é marcado como bash , recomendo que você use a construção de teste estendida ( [[...]] ) , e esqueça as citações:
if [[ -z && -z ]]; then
...
A menos que você queira compatibilidade sh / POSIX, não há razão para não usar [[ ]] .
Isso também funciona,
if [ "" == "" && "" == ""]; then
echo NULL
fi
Uma abordagem muito frequente é a seguinte:
if [ "x$var1" == "x" ] && [ "x$var2" == "x" ];
then
echo "both variables are null"
fi
Freqüentemente é usado para evitar conseqüências não intencionais, como variáveis não configuradas. Com mais frequência, você verá isso como if [ "x$var" != "x" ]
Tags command-line bash scripts