New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
Running Windows (or anything else) on your Mac Discussion of Classic or running Windows, Linux and other OSes on the Mac.

Terminal.app/bash: Creating An Executable Shell Script


Post Reply New Thread Subscribe

 
Thread Tools
ebay

 
Member Since: Apr 16, 2008
Posts: 36
ebay is an unknown at this point

ebay is offline
I'm wondering what I'm missing here. I'm trying to create a little script that executes in a terminal session. I'm using bash (the default terminal shell). Here's what I did in a terminal session to try to make one--

$ ed mmm
mmm: No such file or directory
i
#!/bin/bash
echo "Hello World!"
.
w
32
q
$ ls -l mmm
-rw-r--r-- 1 markhenri staff 32 Apr 28 10:24 mmm
$ chmod +x mmm
$ ls -l mmm
-rwxr-xr-x 1 markhenri staff 32 Apr 28 10:24 mmm
$ mmm
-bash: mmm: command not found
$ bash mmm
Hello World!
$ sh mmm
Hello World!
$



Seems like this should be an executable file? On line docs say this is how you do it. Is it something with my rights/privileges? I tried mmm.sh also as well as #!/bin/sh in the first line. The script runs fine if you invoke the shell command before it. Odd?
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
try ./mmm

mikeMbp:~ mike$ ls -l mmm
-rw-r--r-- 1 mike staff 31 Apr 28 10:37 mmm
mikeMbp:~ mike$ chmod 755 mmm
mikeMbp:~ mike$ cat mmm
#!/bin/bash
echo "Hello World"
mikeMbp:~ mike$ ./mmm
Hello World


it's not in the path.

mikeMbp:~ mike$ sudo cp mmm /usr/local/bin
mikeMbp:~ mike$ mmm
Hello World
mikeMbp:~ mike$

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
ebay

 
Member Since: Apr 16, 2008
Posts: 36
ebay is an unknown at this point

ebay is offline
That worked.

I didn't have a /usr/local/bin directory so I created one.

It was in my path though?

I guess my question is about scripts in general. On Win XP, I used to write batch files for doing ftp uploads and just leave them laying around whatever directory I was working in. When I'd finish working on the file, I'd just execute the batch file and up it would go. It was convenient because I didn't have to go into my FTP client or start issuing change dir commands all all that.

Is there a Mac equivalent way to do this? It sort of appears that this would go against the security model on Unix and it's probably why PC's are notoriously vulnerable to malicious code. Am I getting this?
QUOTE Thanks
GroovyLinuxGuy

 
GroovyLinuxGuy's Avatar
 
Member Since: Apr 03, 2006
Location: Edmonton, Canada
Posts: 125
GroovyLinuxGuy will become famous soon enough
Mac Specs: 15" MacBook Pro, 12" iBook G4, 14" iBook G4 running Ubuntu 7.10

GroovyLinuxGuy is offline
Quote:
Originally Posted by ebay View Post
That worked.

I didn't have a /usr/local/bin directory so I created one.

It was in my path though?

I guess my question is about scripts in general. On Win XP, I used to write batch files for doing ftp uploads and just leave them laying around whatever directory I was working in. When I'd finish working on the file, I'd just execute the batch file and up it would go. It was convenient because I didn't have to go into my FTP client or start issuing change dir commands all all that.

Is there a Mac equivalent way to do this? It sort of appears that this would go against the security model on Unix and it's probably why PC's are notoriously vulnerable to malicious code. Am I getting this?
You are not using Windows anymore...remember that you are doing things the *nix way now. You either prefix it with ./ or call it from another directory or have it in your path.

Hmm...what I wrote sound kinda snippy...I don't mean it to sound that way. No offence meant if any taken.

Cheers
QUOTE Thanks
ebay

 
Member Since: Apr 16, 2008
Posts: 36
ebay is an unknown at this point

ebay is offline
Ha ha, no offense taken! Very grateful for your comments.

OT: I'm still detoxing from Windows. I'm on day 7. It's going pretty good. A prospective client suggested that I load Windows on my Mac and I just about had a hissy-fit. He said, and I quote, "you could always slap Windows on..." I felt cheap and dirty afterward.

I did notice that I could suffix the file with .mybatch (whatever) and open it from finder where it asked for an association with that suffix. If I chose terminal.app, it ran it. Am I straying here?
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
To view your current path type
echo $PATH

in your terminal

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
Quote:
Originally Posted by ebay View Post
Ha ha, no offense taken! Very grateful for your comments.

OT: I'm still detoxing from Windows. I'm on day 7. It's going pretty good. A prospective client suggested that I load Windows on my Mac and I just about had a hissy-fit. He said, and I quote, "you could always slap Windows on..." I felt cheap and dirty afterward.

I did notice that I could suffix the file with .mybatch (whatever) and open it from finder where it asked for an association with that suffix. If I chose terminal.app, it ran it. Am I straying here?
you should be able to run it that way from finder. Personally most of my scripts are run via cron.

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
GroovyLinuxGuy

 
GroovyLinuxGuy's Avatar
 
Member Since: Apr 03, 2006
Location: Edmonton, Canada
Posts: 125
GroovyLinuxGuy will become famous soon enough
Mac Specs: 15" MacBook Pro, 12" iBook G4, 14" iBook G4 running Ubuntu 7.10

GroovyLinuxGuy is offline
Quote:
Originally Posted by ebay View Post
Ha ha, no offense taken! Very grateful for your comments.

OT: I'm still detoxing from Windows. I'm on day 7. It's going pretty good. A prospective client suggested that I load Windows on my Mac and I just about had a hissy-fit. He said, and I quote, "you could always slap Windows on..." I felt cheap and dirty afterward.

I did notice that I could suffix the file with .mybatch (whatever) and open it from finder where it asked for an association with that suffix. If I chose terminal.app, it ran it. Am I straying here?
Yup...if it works, then it works...

Most of my scripts are run out of my bin directory in my home...I just added it to my path...
QUOTE Thanks

Post Reply New Thread Subscribe


« Mac OS 9.2 Screenshot Help | School Windows Requirments Met by MBP? »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Making a Shell Script Executable surfwax95 OS X - Development and Darwin 10 08-25-2010 05:15 PM
shell script xml MrGecko OS X - Development and Darwin 4 10-03-2006 08:44 AM
creating script for system login pbook24 Schweb's Lounge 3 01-30-2006 04:14 PM
Shell script question Niwrad OS X - Development and Darwin 14 06-28-2005 05:58 PM
Shell Script on Desktop starrin OS X - Operating System 2 07-28-2004 12:25 PM

All times are GMT -4. The time now is 05:24 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?