How do I create a shell script on a Macintosh?
A reader writes:
I've started to go through your shell script book Wicked Cool Shell Scripts but there is still something I'm unclear on. I'm showing my ignorance here, but how exactly do you save a shell script so you can use it later?"
If you're comfortable using the vi editor within the Mac OS X environment, your best bet is to open up a Terminal window (Applications -> Utilities -> Terminal) and type in the script directly.
If not, you can use an application like BBEdit, save the file as text-only with or without line breaks, then open up the Terminal application and type in the name of the script, as in sh myscript.sh (assuming you saved the file as 'myscript.sh').
The final step is for you to actually make the script executable, which you can do by using the chmod command, as in: chmod +x myscript.sh.
Once you've done that - particularly if you have the script in one of the directories in your PATH - you can execute the script by simply typing its name at the command line.
Related Shell Script Programming articles:
✔ Secretly capture screenshots on my Mac?
When I used to work on a Linux system, there was a utility we had that would let me take screen captures every...✔ Parsing "id" strings in a Shell Script?
Hello Dave. I need a Bash shell script that creates a directories with the group names automatically when user logs in to the...✔ Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...✔ Script to test line lengths for Twitter compatibility?
I've been tasked with writing a series of tweets for a Black Friday marketing campaign and am finding it a bit tricky because...✔ Shell script to convert lowercase to title case?
As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
I do have a comment, now that you mention it!
Check This Out Too...
Look for Answers
All Our Categories
Apple iPad Help
Articles and Reviews
Auctions and Online Shopping
Blogs and Blogging
Building Web Site Traffic
Business and Management
Computer and Internet Basics
d) None of the Above
Google Gmail Help
Google Plus Help
Industry News and Trade Shows
iPhone and Cell Phone Help
iPod, Sony PSP and MP3 Player Help
Kindle Fire Help
Mac OS X Help
Pay Per Click (PPC) Advertising
Search Engine Optimization (SEO)
Shell Script Programming
Tech Support Video Help
The Writing Business
Twitter, LinkedIn and Social Network Help
Unix and Linux Help
Video Game Tips and Help
Windows PC Help
Find Me on Google+
ADT on G+