Sto provando a confrontare le stringhe in bash. Ho già trovato una risposta su come farlo su stackoverflow. In sceneggiatura che sto cercando, io sto usando il codice presentato da Adam nella questione di cui:Confronto di stringhe in bash. [[: non trovato
#!/bin/bash
string='My string';
if [[ "$string" == *My* ]]
then
echo "It's there!";
fi
needle='y s'
if [[ "$string" == *"$needle"* ]]; then
echo "haystack '$string' contains needle '$needle'"
fi
Ho anche provato l'approccio da ubuntuforums che si può trovare nel 2 ° posto
if [[ $var =~ regexp ]]; then
#do something
fi
In entrambi i casi ho ricezione errore:
[[: not found
Cosa sto facendo male?
Potrei sbagliarmi, ma usare una singola parentesi quadra ha sempre funzionato per me. –
Cosa stampa '/ bin/bash --version'? – themel
GNU bash, versione 4.2.8 (1) – user1581900