Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rating: Thread Rating: 13 votes, 5.00 average. Display Modes
Old 07-03-2002, 05:37 AM   #1
kate
Prospect
 
Join Date: May 2002
Location: Europe
Posts: 45
shell scripting greenhorn question.....

When I create a shell script like the following:
#!/bin/sh
cd /Volumes/Internet/eDonkey2000/mldonkey-distrib/
./mldonkey > mldonkeylog.log

how do I manage to make the script work by a command?

Do I need a file like mycommand.command and put it into a specific directory?

I tried to do this and placed mycommand.command on the desktop, but I always get an error message that the file could not be found.

What I want to have is getting the script to work after entering e.g. donky<return> in the terminal.
kate is offline   Reply With Quote
Old 07-03-2002, 07:21 AM   #2
Novajo
Triple-A Player
 
Join Date: Jan 2002
Location: Toronto, Canada
Posts: 185
Make it executable with chmod ogu+x filename
Put it in a directory that is in your path. Check your path with:
echo $PATH. I would recommend that you put it in /Users/yourname/bin/. Create the directory if it does not exist. Move the file there, then type: rehash (to reinitialize your path programs). By the way, you could run it from the desktop if you use its full path. If a program is not executable, call it with

sh filename.
__________________
Novajo
Novajo is offline   Reply With Quote
Old 07-03-2002, 07:31 AM   #3
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
a couple of things need to be done.

1. make it "executable"
2. put it in your "path"

it does not need to be extension'd with .command, but that enables it to be finder
double-clickable.

to make it executable, you'll want to change it's file "mode":
Code:
% chmod u+x donkey
to put it in your path, examine your PATH variable, decide where it belongs, copy
it to the target dir:
Code:
% echo $PATH

/Users/merv/bin:/sw/bin:/sw/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

# if you want the script installed just for your user account, move it to your
# ~/bin dir ; if you want it installed system wide, move it to /usr/local/bin
 
# you may need to mkdir ~/bin and modify your login script to add your 
# ~/bin to your path

% mv donkey ~/bin

# if you're running a csh shell, you'll need to rehash your path to get it to be
# immediately recognized

% rehash

# test your script

% donkey
your script still is a little wonky. your script cd's and runs a script?

why not execute it directly?
Code:
#!/bin/sh

# file: ~/bin/donkey - run mldonkey

# always use full paths to files in scripts

# prepare a tmp dir for easy cleanup, it is bad form to have log file turds 
# all over the filesystem

[ -d ~/tmp ] || /bin/mkdir ~/tmp    # ~/tmp there ? if not, create it

/Volumes/Internet/eDonkey2000/mldonkey-distrib/mldonkey > \
  ~/tmp/mldonkeylog.log
study that and let us know how it goes.

[edit: Novajo, what are you doing up?! you beat me to it]

Last edited by mervTormel; 07-03-2002 at 07:46 AM.
mervTormel is offline   Reply With Quote
Old 07-03-2002, 09:14 AM   #4
kate
Prospect
 
Join Date: May 2002
Location: Europe
Posts: 45
thanks to all of you, that did help a lot!

kate is offline   Reply With Quote
Reply


Posting 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

Forum Jump



All times are GMT -5. The time now is 10:10 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.