Question

I am calling a script with argument as "incr":

script.sh incr

I need to check if the argument passed is "incr" or not.

Also, "incr" can be any argument,not necessarily the first. For ex :

script.sh -l incr

Any general way to check if any argument is "incr" or not.

Was it helpful?

Solution

If you want to know if a particular argument is a string, the answer is "yes". All arguments are strings. If you want to know if an argument is a particular string, check it:

for arg; do
  if test "$arg" = incr; then
    echo incr is passed as an argument
  fi
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top