Sto provando a passare argomenti a una funzione all'interno di un'istruzione if e quindi a valutare cosa restituisce la funzione (in bash). Il risultato che ottengo è errato. Come lo fai correttamente?Passare argomenti a una funzione all'interno di un'istruzione if in bash
#!/bin/bash
foo() {
if [ $1 = "zero" ]; then
echo "0"
else
echo "1"
fi
}
arg="zero"
if foo $arg -eq 0 ; then
echo "entered 0"
else
echo "entered something else"
fi
arg="blah"
if foo $arg -eq 0 ; then
echo "entered 0"
else
echo "entered something else"
fi
Non
i risultati desiderati:
[email protected]:~/work$ ./test.sh
0
entered 0
1
entered 0
Grazie in anticipo. ~ Chris
Grande grazie !! – user1117603