Wednesday, August 22, 2018

shell input validation

shell scripting STINKS, and to make it better we should at least make it more robust.

For instance by validating input parameters

Arrays are a great and simple way to achieve this.

array=(pippo pluto topolino)
printf '%s ' "${array[@]}"
printf  '\n'
value=puppo
if [[ ! " ${array[@]} " =~ " ${value} " ]]; then
  echo "array doesnt contain value $value"
fi





No comments: