Using custom shell scripts on OSX or Linux
Custom shell scripts allow you to do pretty much anything. Here's a short tutorial on how to set up either OSX or Linux so you can use custom shell scripts on your system.
Configuring your environment ¶
I’m assuming here that you are on a POSIX compliant system (namely OSX or Linux). First let’s make sure we are in our home directory. On OSX or Linux in a terminal run:
cd
Standard practice is to keep user shell scripts in a bin folder in your home directory. You may or may not have this folder depending on your operating system. If it doesn’t exist create it:
mkdir bin
So on OSX the folder path will be /Users/george/bin
. On Linux it will be
/home/george/bin
. Remember ‘george’ will be whatever your username is.
Ensuring bin is in your path ¶
To be able to use the shell scripts from our bin
folder we need to make sure
that this folder is in the $PATH
variable. The shell looks in this folder when
you issue a command.
If you are comfortable with vi use these commands. If you are not comfortable with vi use your text editor of choice.
cd #change to home directory
vi .bash_profile
Add the following line to this file
PATH=$PATH:$HOME/bin
For the changes to take effect you need to reload your profile. I’m assuming you are still in your home directory.
source ~/.bash_profile
Adding scripts ¶
Now we can just drop shell scripts into the bin folder. To use them we must make sure they are executable: chmod +x yourshellscript.sh
That’s it. Now you can call your shell script from the command line using
yourshellscript.sh
Related reading ¶
- Shell Script - Wikipedia
- Shell Scripting Primer
- OS X: Change your PATH environment variable
- HOWTO: Add a Directory to my Path Statement/Variable
Tags
Can you help make this article better? You can edit it here and send me a pull request.
See Also
-
ExpressionEngine permissions shell script
Every ExpressionEngine install requires that a number of permissions are set on folders and files. Here's a shell script to do the hard work for you. -
Ubuntu 9.04 Jaunty Jackalope Released
The latest release of Ubuntu is now available, featuring faster boot times, a growl-style notification system and updates to bundled software. -
Testing with IE6, IE7 and IE8 on VirtualBox
I've recently moved from using Parallels for browser testing to Sun's Open Source VirtualBox. Here's a walkthrough on how to get a browser testing suite for free on OSX or Ubuntu.