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.

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top