Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How to make shell script that does this?

How to make shell script that does this?
Thread Tools
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Dec 20, 2008, 10:58 PM
 
I'm having trouble making a SH shell script. I'm trying to have it accept 2 arguments, and then execute a command line app, passing the 2 arguments into the arguments of the command line app it's calling, along with some other arguments that are static. In addition, the execute it calls is not a hard coded path, but rather in the same directory the SH shell script is running in.

Any pointers? Thanks!
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 20, 2008, 11:17 PM
 
Easy... $0 = the original command, $1 = argument one, $2 = argument two, etc.

So, for example:

sh myscript.sh --source /path1 --dest /path2

$1 = --source
$2 = /path1
$3 = --dest
$4 = /path2
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 20, 2008, 11:51 PM
 
I'm not sure how much "pointer" you're looking for, so here's the general form of what you want to do:

Code:
if [ $# -ne 2 ]; then echo "I TAKE TWO ARGUMENTS, GENIUS!" else ./somecommand $@ -staticarg -anotherstaticarg fi
(Last edited by Chuckit; Dec 20, 2008 at 11:59 PM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
timmerk  (op)
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Dec 22, 2008, 12:10 PM
 
Thanks guys! I'll give it a shot.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:51 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2