Quantcast
Channel: Java mon amour
Viewing all articles
Browse latest Browse all 1121

bash comparison and validation of string

$
0
0
trying to understand Bash syntax is really wasted time.... just copy/paste working examples



array=("pippo pluto topolino")
value=pluto

[[ " ${array[@]} " =~ " ${value} " ]] && echo "YES" || echo "NO"

if [[ " ${array[@]} " =~ " ${value} " ]]; then echo trovato; fi

pippo="ciao"
[[ $pippo = "ciao" ]] && echo "1yes"
[[ "ciao" = "ciao" ]] && echo "2yes"

x="valid"
if [ "$x" = "valid" ]; then
echo "x has the value 'valid'"
fi

[[ "$x" = "valid" ]] && echo "x is valid"

[ "$x" == "valid" ] && echo "x has the value 'valid'"

[ "$x" == "valid" ] && echo "i am valid" || echo "i am invalid"


Viewing all articles
Browse latest Browse all 1121

Trending Articles