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
timmerk
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Dec 21, 2008, 12:58 AM
 
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!
     
besson3c
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Dec 21, 2008, 01:17 AM
 
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
     
Chuckit
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Dec 21, 2008, 01:51 AM
 
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 21, 2008 at 01:59 AM. )
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, 02:10 PM
 
Thanks guys! I'll give it a shot.
     
   
 
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
Top
Privacy Policy
All times are GMT -4. The time now is 10:54 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,