After clicking on the Terminal icon you will be greated with a "Terminal - bash" prompt. As a minimum there a few commands that you should be familiar with:
-
ls -l ....... directory listing of files
-
ls-al ...... directory listing of files including hidden files (prefixed with .)
-
rm ........ remove a file
-
rm -R .... remove a directory
-
mkdir .... make a directory
-
cd ......... change directory
-
cp ......... copy file
-
mv ........ move file
-
set ........ show environment variables
-
~ home path (/Users/loginName)
-
. current directory (single dot)
-
.. prior directory (double dot)
Let's create a HelloWorld script.
Start by typing "pico HelloWorld" and hit enter (as shown in image below)
Type in "echo hello world!" as shown above.
Hold Ctrl key and press X (to Exit). When prompted to save modified buffer answer "Y" for yes. Hit enter to accept the name "HelloWorld".
Type in "ls -l" and hit enter, you should find your file in the list with -rw-r--r-- (read write) priviledges.
Execute the "chmod 755 HelloWorld" command which assigns E"x"ecute permission for the newly created script.
If you attempt to run this command by typing "HelloWorld" and hitting enter you will most likely (default configuration) be greeted with a "command not found". Oddly, the operating system doesn't look in the current directly for commands unless you specifically specify "this location" by using the dot command, e.g., "./HelloWorld" will work.
Obviously this is not practical so I made some easy configuration changes that make my life simpler.
Execute "pico .bash_profile" and add ".:~/bin:$PATH" to the export Path command (ensure there is no space between PATH and the equal sign) as shown in the image below.
The colon is a delimiter between paths (to search for commands in) and the dot tells it to search the current path, preventing you from having to use ./mycommand. The ~/bin assumes you created a bin command (md bin) which you can easily use to place your scripts in. For example:
cp HelloWorld bin
would copy the HelloWorld executable script to the bin folder, now you can execute it from anywhere in the system.
The $PATH statement indicates that you want the existing path to be appended to the newly assigned path.
Notice below that in the PATH statement that the "~/bin" was transformed into the actual location "/Users/Bill/bin".