I have a bash script where I pass an argument
./chris.bash "\argv Test"
I want to detect if the user supplied \argv at the start of the argument
I have a bash script where I pass an argument
./chris.bash "\argv Test"
I want to detect if the user supplied \argv at the start of the argument
echo "$1" | grep -q "^[\\]argv" || echo Invalid argument
Have tried it in my script but is not printing anything. It works on the command line though.
I came up with
if [[ "$1" =~ ^[\\]argv* ]]; then
msg=`echo "$1" | awk 'BEGIN {FS="argv"} {print $2}' | sed 's/^ *//g'`
# Removes the "\argv" and any leading spaces
echo "$msg"
fi
Or, in bash and ksh (and perhaps others) ...
msg=${1/#\\argv*( )}
Depending on how your bash is configured, you may need to enable extended globbing:
shopt -s extglob
Regards,
Alister