Me vendría bien un poco de ayuda con mi declaración IF y &&. No funciona y nada de lo que intento funciona tampoco. Quizás alguien pueda ver el problema:
if [[ $thisvariable="yes" && grep 'this string' ./"$thisfile".txt ]]; then
Esto simplemente no funciona. ¿Alguien ve algún problema?
Respuesta1
Prueba esto:
if [[ "$thisvariable" = "yes" ]] && grep -q 'this string' ./"${thisfile}".txt; then
Respuesta2
Recién estoy viendo la última publicación, así que no lo intenté. Finalmente logré que funcionara con esto:
if [ $thisvariable == yes ] && [ "`grep 'this string' ./"thisfile"`" ]; then
Respuesta3
La [
construcción no puede aceptar múltiples condiciones. Lo que estás intentando se puede escribir de varias maneras:
if [ "$thisvariable" = "yes" ] && grep 'this string' ./"thisfile" > /dev/null
then
echo yes;
fi
o, más simplemente
[ "$thisvariable" = "yes" ] && grep 'this string' ./"thisfile" > /dev/null && echo yes
Respuesta4
De:http://tldp.org/LDP/abs/html/comparison-ops.html#SCOMPARISON1
if [ "$a" = "$b" ]
¡Precaución!, observe el espacio en blanco que enmarca el "=".
if [ "$a"="$b" ] is not equivalent to the above.