Passing and using arguments in Scripts.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing and using arguments in Scripts.
# 1  
Old 11-13-2006
Passing and using arguments in Scripts.

I am new to scripting in AIX / UNIX. I have a script that runs 4 other scripts and I want to be able to pass in a agrument that I can check before I run the next script to see if the previous script finished with no errors.

Can someone send me an example of this as I'm sure it's pretty easy to do....as long as you know how.

Thanks,

David.Vilmain
david.vilmain@wush.com
# 2  
Old 11-13-2006
You can check the exit code after each of the four scripts you run, from insode your main script. If the first script exits with a status of 0 then continue with the second and then check it, etc....

eg

#Placing scripts to run in loop

for next in `echo "script1.sh script2.sh script3.sh script4.sh"`
do
/path/to/$next
done=$?
if [ $done -ne 0 ]
then
echo "FAILED - $next"
break
fi
done

If you want to pass arguments to a script you can place them on the command line and capture them inside the script using the standard $1, $2
eg

/path/to/script1.sh arg1 arg2

script1.sh would look like.....
#!/bin/sh
value1=$1
value2=$2
echo "$1 - $2"

Hope this is what your after
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

2. Shell Programming and Scripting

Passing arguments at runtime

Hi .. Can any one please tell how to pass argument to shell script at runtime? I want to implement funcnality just like bc, where we can provide input while script is running and can be used later in the same script. Thanks in advance... (1 Reply)
Discussion started by: kunjalhg
1 Replies

3. UNIX for Dummies Questions & Answers

Passing arguments

I need to pass arguments to a shell script.My batch is calling some java program. ################# x=$1 y=$2 java -classpath program ################### if first parameter and second parameter is null then java -classpath program if first parameter is not null and second parameter is... (3 Replies)
Discussion started by: mnjx
3 Replies

4. Shell Programming and Scripting

Passing arguments to awk

I have an awk script below which I call using for example awk -f ../../A-Scripts/select-model.awk iterations.txt 16x12 10 I want to be able to use it in a different way like this awk -f ../../A-Scripts/select-model.awk iterations.txt nxz=16x12 iter=10 or awk -f... (1 Reply)
Discussion started by: kristinu
1 Replies

5. Shell Programming and Scripting

passing arguments

Hi I have a script to which I pass multiple arguments, for example lets say the script name is "abc". I run the script like ./abc def /file <directory location> In the above "def" is the first argument and "/file" is the second argument. I expect <directory location> that is passed after... (4 Replies)
Discussion started by: zmfcat1
4 Replies

6. Shell Programming and Scripting

Passing Arguments in Shell Scripts

Hello everybody! First time posting here:) Right, I am trying to pass arguments in my shell scripts using $1, $2 and $3 etc using if else statement........ This is my shell script which is based on serching the google website #!/bin/sh wget -t1 -E -e robots=off - -awGet.log -T 200 -H... (47 Replies)
Discussion started by: kev_1234
47 Replies

7. Shell Programming and Scripting

Passing Arguments-Help

Hi, I have a script which adds the user credentials to an ldap server. Im passing the variables as below.. /path/my_script $uname $pwd $environ ${deposit} If i enter some special characters like ';' in $pwd, script returns an error which is set to display if the user enters... (5 Replies)
Discussion started by: Tuxidow
5 Replies

8. UNIX for Dummies Questions & Answers

passing strings as arguments

Is it possible to pass a string as an argument from the command line? I know I can pass a word in but can I put a line of text in with spaces and fullstops or do I just put it in brackets or quotes so the compiler can differinate between the first argument and the second. (1 Reply)
Discussion started by: iago
1 Replies

9. UNIX for Dummies Questions & Answers

Passing arguments to an alias

I want to have an alias for the command fold -78 filename | lp How do I set my alias so that the argument passed is filename ?? alias lp='fold -78 | lp' then lp filename wont work cuase this is fold -78 | lp filename (1 Reply)
Discussion started by: pmcg
1 Replies

10. UNIX for Dummies Questions & Answers

passing arguments

I'm trying to pass a filename, or all the files in the current directory to the ls command with a script. Unsuccessful so far, here are a few of my attempts: #!/bin/ksh read fname #if (( $# > 0 )); then $fname | ls -l #fi this produces a long listing of all the files in my current... (4 Replies)
Discussion started by: jpprial
4 Replies
Login or Register to Ask a Question