# ---------------------------------------------------------------------------- # How to check if a string begins with some value in bash # # more cool examples here: https://www.cyberciti.biz/faq/bash-check-if-string-starts-with-character-such-as/ # ---------------------------------------------------------------------------- # # Let us define a shell variable called vech as follows: vech="Bus" # To check if string “Bus” stored in $vech starts with “B”, run: [[ $vech = B* ]] && echo "Start with B" # The [[ used to execute the conditional command. It checks if $vech starts with “B” followed by any character. Set vech to something else and try it again: vech="Car" [[ $vech = B* ]] && echo "Start with B" [[ $vech = B* ]] && echo "Start with B" || echo "Not matched" # longer version with if input="xBus" if [[ $input = B* ]] then echo "Start with B" else echo "No match" fi # ---------------------------------------------------------------------------- # Check number of arguments passed to a Bash script # # https://stackoverflow.com/questions/18568706/check-number-of-arguments-passed-to-a-bash-script # ---------------------------------------------------------------------------- if [ "$#" -ne 1 ]; then echo "Illegal number of parameters" fi # Or if test "$#" -ne 1; then echo "Illegal number of parameters" fi