Need to run the script by argument passing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to run the script by argument passing
# 1  
Old 08-21-2009
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


Code:
#!/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

# 2  
Old 08-21-2009
One way:

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

(Reference: example of command-line parameter handling)
# 3  
Old 08-21-2009
Hi So according to Dr, i changed my script as below. How do i used usage instead?

-Aditya

Code:
#!/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
# 4  
Old 08-21-2009
something like this :
Code:
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variable as an argument to another script

Hi, I am trying to pass a variable as an argument to another script. While substitution of variable, I am facing a problem. varaiable "a" value should be -b "FPT MAIN". When we pass "a" to another script, we are expecing it to get substitue as ./test.sh -b "FPT MAIN". But, it is getting... (9 Replies)
Discussion started by: Manasa Pradeep
9 Replies

2. Shell Programming and Scripting

passing argument in script?

hi, I want to implement some function to perform following task if ; then $TEXT = "Data_0" else $TEXT = $1 fi if ; then $Lines = 45 else $Lines = $2 fi Kindly suggest, thanks (11 Replies)
Discussion started by: nrjrasaxena
11 Replies

3. Shell Programming and Scripting

Passing argument from Java to Shell script

Hi All, I want to pass array of argument from Java to a shell script.I can use process builder api and its exec() method to call the script,but the question is how to receive the parameter in the script. Thanks in advance ---------- Post updated at 10:00 PM ---------- Previous update was... (1 Reply)
Discussion started by: Abhijeet_Atti
1 Replies

4. Shell Programming and Scripting

Passing --usage as argument to awk script

I have the awk script below and things go wrong when I do awk -v dsrmx=25 -f ./checkSRDry.awk --usage I basically want to override the usual --usage and --help that awk gives. How do people usually handle this situation when you also want to supply your own usage and help concerning the... (2 Replies)
Discussion started by: kristinu
2 Replies

5. Shell Programming and Scripting

Make script that run with argument if not run from configuration file argument

Hello, Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file i.e I am workiing on a script which will run through crontab and the script will chekout the code ,zip and copy to the... (3 Replies)
Discussion started by: rohit22hamirpur
3 Replies

6. Shell Programming and Scripting

Its Urgent ::: Passing Argument during Script Execution

Dear All, Plz, can someone clarify me regarding the below. Actually I want to write the script that will get the some parameter like "yes" or "No" as we wish during execution without prompting for entering that word. Plz tell me... Its Urgent.. Thanks & Regards ... (1 Reply)
Discussion started by: ks47
1 Replies

7. UNIX for Dummies Questions & Answers

Passing command output as an argument to a shell script

Hi, I have a very small requirement where i need to pass command output as an argument while invoking the shell script.. I need to call like this sh testscript.sh ' ls -t Appl*and*abc* | head -n 1' This will list one file name as ana argument.. I will be using "$1" in the shell... (2 Replies)
Discussion started by: pssandeep
2 Replies

8. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies

9. Shell Programming and Scripting

Passing argument from one script to other

Dear All, I have one script which accepts database name and user_id from the user, i have another script that will unload the data from all the tables based on the user_id accepted by the user. How can i pass the user_id from the 1st script to the other. My OS is sun solaris. Thanks in... (3 Replies)
Discussion started by: lloydnwo
3 Replies

10. UNIX for Dummies Questions & Answers

Passing argument to awk script

I am writing a shell script. Now i need to read in a string and send it to an awk file to compare and search for compatible record. I wrote it like tat: read serial | awk -f generate.awk data.dat p/s: the data file got 6 field. According to an expert, we can write it like tat: read... (1 Reply)
Discussion started by: AkumaTay
1 Replies
Login or Register to Ask a Question