The basics of shell scripting

Apple posted a set of pages (also available as a PDF) on basic shell scripting on their developer site. For those that use (or want to use) do shell script it’s a good read.

http://developer.apple.com/documentation/OpenSource/Conceptual/ShellScripting/index.html

I had found these earlier today, but was brought to a halt almost immediately. If you try to write a script in the terminal, it executes every line as you hit return. An instruction like “save the script…” makes no sense - how do you write a script consisting of more than one line? There is no mention of that.

Create it as a text file. (I believe the .sh extension is common for this.)

Bruce is exactly correct. There is no interactive scripting with the shell, you can execute commands, but if you want to run a script you need to create it in a file. Also note that you have to give the file execute privileges!

TextEdit will let you create a plain text file WITHOUT the txt file extension but you have to a) turn off “hide extension” and b)answer a dialog box that says “the file seems to have the extension .sh, do you want to append .txt?” and tell it no.

Thank you both. I’ll use BBEdit to do it.

Typically, I’ve been writing these as a text variable in AS and then running them from a do shell script construct, and I’m not sure that’s less efficient than opening BBEdit, writing the script, blessing it with the correct permissions, and then running it in the terminal or iTerm.