If I want a series of commands to be run by terminal, instead of writing it in a text file and copying and pasting it in there, could I have terminal run it? If so, what does the extension have to be?
The accepted answer is misleading. On OS X (and U*x generally), the name of the file doesn't matter at all. What matters is that it needs to have executable permission (
chmod +x file) and a correct shebang line.
bash$ cat > randomness #!/bin/sh echo Hello, world Ctrl+D bash$ chmod +x randomness bash$ ./randomness Hello, world bash$
The first line looks like a comment, but it's a comment in a special format, called a shebang (short for sharp-bang, common names for the characters
!). The two characters need to be immediately followed by the absolute path name to the interpreter which this script should be interpreted by (optionally followed by whitespace and options for the interpreter; for portability reasons, only a single option string is allowed).
Just write/paste your commands in TextEdit app then save it to desktop .rtf, and once its on the desktop press on the title and rename to your preferred extension. A window will pop up asking you if you are sure you want to save as... select your option. Done. The icon should change to represent the app that can open the extension. Good luck.