# set default variable value first_var=${1:-first} echo${first_var}
# set the default value for variable user if it does not have one echo${user:=second}
# warn # var=${1:=defaultValue} ### FAIL with an error cannot assign in this way # var=${1:-defaultValue} ### Perfect
# display error message third_var=${3:?"Third argument is not definied or empty"} fourth_var=${4:"Fourth argument is not definied"}
# display error message and run command fifth_var=${5:? "Fifth argument is not definied or empty and print current dir" $(pwd)}
# variable length echo${#var}
# strip string varibale msg="who.is.my.love" # front strip echo${msg#*.}# shortest match begin from front, result: is.my.love echo${msg##*.}# longest match begin from front, result: love
# back strip echo${msg%.*}# shortest match begin from end, result: who.is.my echo${msg%%*.}# longest match begin from end, result: who