Need to run the script by argument passing

Hi All,

I have a question regarding running this script by passing an argument, for example ./ShellParse.sh sun, how do i do that? So i want when i pass argument sun, it shouild execute things inside the for loop. I want to support some other platforms too, so there are more for loops to come.
How do i do that?

Thanks
Adsi

#!/bin/sh

ECHO=/bin/echo
FIND=/bin/find
AWK=/bin/awk
LS=/bin/ls
GREP=/bin/grep

ROOT_PATH=/net/icebox/vol/local_images/spins
STREAM_PATH=$ROOT_PATH/7.1

SUN_PLATFORM=`$FIND $STREAM_PATH . -depth -name ShareableEntities | $AWK -F"/" '{if($10 ~ /sun
5/) print $0}'`

for i in $SUN_PLATFORM
do
$ECHO $i
$LS $i | $GREP .su | $AWK -F"_" '{print $1}'
done | sort | uniq -c

One way:

case "$1" in
"sun")
  # for loop
;;
esac

(Reference: example of command-line parameter handling)

Hi So according to Dr, i changed my script as below. How do i used usage instead?

-Aditya

#!/bin/sh

ECHO=/bin/echo
FIND=/bin/find
AWK=/bin/awk
LS=/bin/ls
GREP=/bin/grep

ROOT_PATH=/net/icebox/vol/local_images/spins
STREAM_PATH=$ROOT_PATH/7.1

SUN_PLATFORM=`$FIND $STREAM_PATH . -depth -name ShareableEntities | $AWK -F"/" '{if($10 ~ /sun
5/) print $0}'`
echo -n "Enter Platform you want to run"
read PLAT
case $PLAT in
sun)for i in $SUN_PLATFORM
do
$ECHO $i
$LS $i | $GREP .su | $AWK -F"_" '{print $1}'
done | sort | uniq -c
;;
esac

---------- Post updated at 07:07 AM ---------- Previous update was at 06:59 AM ----------

How do i do it with using getopts

something like this :

while getopts ":a:u" opt; do
  case $opt in
    a)
      echo "-a was triggered!" >&2
      ;;
    u)
      echo "-u was triggered!" >&2
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      ;;
  esac
done