Search code examples
shellunixhp-ux

Getting the list of arguments passed to a method in unix


I have a shell script that is calling another script passing some variable number of arguments.

One of the argument(dont know the position of the argument) will be name "temp".

In another script,i need to test if any of the argument recieved is "test" from the list of arguments and do some calculations based on that.

I know that $1 is the first argument, $@ is all of them and all function parameters can be access via $1,$2..$N.

I need a way so that i can get all the arguments in an Array or something and then i can check in that array whether "temp" is present or not.

I am new to UNIX and i dont know how to implement this. Any help would be highly appreciated.


Solution

  • Something like this ?...

    #!/bin/sh
    
    if [ $(echo $* | grep -c temp) -eq 0 ]
    then
      echo "not found"
    else
      echo "found"
    fi