Script parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script parameter
# 1  
Old 06-10-2013
Script parameter

Hello!

I have a question about scripts with parameters.
I have a install script and i want it to start the daemon if the install_script has the parameter start at execution.

If there is not a parameter it should just do the install routine and leave the start part untouched.

But i dont want to copy the whole script twice
Code:
case $1 in
 start)
    [...whole script with start]
 * ) 
    [...script without start routine]
esac

Is something like this possible?


kind regards
# 2  
Old 06-10-2013
This one ways to do it. (move code to run everytime after esac)
This will run #normal script every time
Code:
#!/bin/bash
# start block
case $1 in
 start)
   <some start code>
   <some start code>
esac

#normal script
<some code>
<some code>

To run only start code when start is added
Code:
#!/bin/bash
# start block
case $1 in
 start)
   <some start code>
   <some start code>
   exit 0
esac

#normal script
<some code>
<some code>

Code:
#!/bin/bash
# start block
if [ "$1" = "start" ]; then
   <some start code>
   <some start code>
fi

#normal script
<some code>
<some code>


Last edited by Jotne; 06-10-2013 at 08:01 AM..
# 3  
Old 06-10-2013
Quote:
Originally Posted by Jotne
This one way to do it.
Code:
#!/bin/bash
# start block
if [ "$1" = "start" ]; then
   <some start code>
   <some start code>
fi

#normal script
<some code>
<some code>

Is this also working the other way around?
Code:
#!/bin/bash
#normal script
<some code>
<some code>

# start block
if [ "$1" = "start" ]; then
   <some start code>
   <some start code>
fi

Because the install stuff has to happen first. Otherwhise it will not start Smilie

kind regards
# 4  
Old 06-10-2013
This way, it will first run normal script and then start script if start is given
# 5  
Old 06-10-2013
Quote:
Originally Posted by Jotne
This way, it will first run normal script and then start script if start is given
So it would be your first example in post #2?

kind regards
# 6  
Old 06-10-2013
Code:
#!/bin/bash
# start block
case $1 in
 start)
   <some start code>
   <some start code>
esac

#normal script
<some code>
<some code>

This will run start block if start is given.
Then it run normal script, regardless of start no start.
Not sure if this is what you want.
# 7  
Old 06-10-2013
Quote:
Originally Posted by Jotne
Code:
#!/bin/bash
# start block
case $1 in
 start)
   <some start code>
   <some start code>
esac

#normal script
<some code>
<some code>

This will run start block if start is given.
Then it run normal script, regardless of start no start.
Not sure if this is what you want.
yeah propably. The thing is that the normal part has to be executed first because otherwhise the start part will not work.

Is it still working if i put the case block at the bottom of the script?

kind regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass script with parameter in korn shell script

I have written a script which will take input parameter as another script. However, if the script passed as input parameter has parameters then this script doesn't work. I have a script b.ksh which has 1 and 2 as parameters I have a script c.ksh which has 3,4 and 5 as parameters vi a.ksh... (1 Reply)
Discussion started by: Vee
1 Replies

2. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

3. UNIX for Dummies Questions & Answers

Passing shell script parameter value to awk command in side the script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff |... (1 Reply)
Discussion started by: Sarita Behera
1 Replies

4. Post Here to Contact Site Administrators and Moderators

Unable to pass shell script parameter value to awk command in side the same script

Variable I have in my shell script diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk -F'~' ''$2 == "$id"' {print $0}' > $new I could see value of $id is not passing to the awk... (0 Replies)
Discussion started by: Ashunayak
0 Replies

5. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

6. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

7. UNIX for Advanced & Expert Users

How to use parameter in sql script pass from unix script?

Hi, I am unable to use parameter in sql script passed from unix script. my sql script CREATE_SBI_LIST_GROUP.sql is like this - ------------------------------- SELECT SDS.ID "SO_ID", SDS.SO a1, sgp.sga__code SGA_CODE, FROM sga sga,sales_genl_provision sgp , comm_product_condn cpc... (2 Replies)
Discussion started by: apskaushik
2 Replies

8. UNIX for Advanced & Expert Users

Pass parameter to the main script from wrapper script

Hi, I am writing a wrapper script(wrap_script.sh) to one of the main scripts (main_script.sh) The main script is executed as following: ./main_script.sh <LIST> <STARTDATE> <ENDDATE> looks for a parameter which is a LIST(consists of different list names that need to be processed), START/END... (0 Replies)
Discussion started by: stunnerz_84
0 Replies

9. Shell Programming and Scripting

passing parameter from Shell-script to Sql-script

Dear Friends, Please help me to achieve the following: I want to pass one parameter from Shell-script to Sql-script. Example: My ShellScript.sh is calling report.sql like this: /bin/sqlplus /reports.sql And My report.sql is calling many Stored-Procedures like this: exec... (0 Replies)
Discussion started by: subodhbansal
0 Replies

10. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies
Login or Register to Ask a Question