Sto tentando di eseguire un blocco di codice se un flag è impostato su true e l'altro su false. cioèTest Boolean Bash
var1=true
var2=false
if [[ $var1 && ! $var2 ]]; then var2="something"; fi
Dal momento che non ha valutato il modo in cui mi aspettavo ho scritto diversi altri casi di test e sto avendo difficoltà a capire come sono in corso di valutazione.
aa=true
bb=false
cc="python"
if [[ "$aa" ]]; then echo "Test0" ; fi
if [[ "$bb" ]]; then echo "Test0.1" ; fi
if [[ !"$aa" ]]; then echo "Test0.2" ; fi
if [[ ! "$aa" ]]; then echo "Test0.3" ; fi
if [[ "$aa" && ! "$bb" ]]; then echo "Test1" ; fi
if [[ "$aa" && ! "$aa" ]]; then echo "Test2" ; fi
if [[ "$aa" ]] && ! [[ "$bb" ]]; then echo "test3" ; fi
if [[ "$aa" ]] && ! [[ "$cc" ]]; then echo "test4" ; fi
if [[ $aa && ! $bb ]]; then echo "Test5" ; fi
if [[ $aa && ! $aa ]]; then echo "Test6" ; fi
if [[ $aa ]] && ! [[ $bb ]]; then echo "test7" ; fi
if [[ $aa ]] && ! [[ $cc ]]; then echo "test8" ; fi
Quando eseguo precedente codeblock l'unico output che ottengo è
Test0
Test0.1
Test0.2
tuttavia, la mia aspettativa è che vorrei get
Tes t0
Test1
Test3
Test5
Test7
ho cercato di capire il modo migliore per eseguire test simili, tuttavia maggior parte degli esempi che ho trovato sono impostati nel formato
se [[ "$ aa" == true]];
che non è proprio quello che voglio fare. Quindi la mia domanda è qual è il modo migliore per fare paragoni come questo, e perché alcuni dei casi di test che mi aspetterei di passare semplicemente no?
Grazie!
Grazie. Dopo aver commentato la riga 'bb = false' e poi riascoltare la sceneggiatura, vedo come funziona, mi ha dato un risultato più in linea con quello che mi aspettavo. – JLMarks
Per inciso, questa è la seconda domanda che ho mai posto su StackOverflow, il primo è [oltre due anni fa] (http://stackoverflow.com/questions/9170155/is-there-a-simple-to-to split-e-ricongiungersi-a-tarfile-con-python). In quella domanda tu dove l'unico utente a rispondermi. Sono appena arrivato ad accettare la tua risposta, quindi grazie! – JLMarks
Contento di aver potuto aiutare. –