
Eu poderia usar um pouco de ajuda com minha instrução IF e &&. Não está funcionando e nada do que estou tentando está funcionando também. Talvez alguém possa ver o problema:
if [[ $thisvariable="yes" && grep 'this string' ./"$thisfile".txt ]]; then
Isso simplesmente não funciona. Alguém vê algum problema?
Responder1
Experimente isto:
if [[ "$thisvariable" = "yes" ]] && grep -q 'this string' ./"${thisfile}".txt; then
Responder2
Só agora estou vendo o último post, então não tentei isso. Finalmente consegui trabalhar com isso:
if [ $thisvariable == yes ] && [ "`grep 'this string' ./"thisfile"`" ]; then
Responder3
A [
construção não pode aceitar múltiplas condições. O que você está tentando pode ser escrito de várias maneiras:
if [ "$thisvariable" = "yes" ] && grep 'this string' ./"thisfile" > /dev/null
then
echo yes;
fi
ou, mais simplesmente
[ "$thisvariable" = "yes" ] && grep 'this string' ./"thisfile" > /dev/null && echo yes
Responder4
De:http://tldp.org/LDP/abs/html/comparison-ops.html#SCOMPARISON1
if [ "$a" = "$b" ]
Cuidado!, observe o espaço em branco emoldurando o "=".
if [ "$a"="$b" ] is not equivalent to the above.