문제

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