Please enable JavaScript eh!

 ⌘ Web Mechanic ⌘ 

Bash Scripting


Shell / Environment Variables

We call them 'variables' because of the way we refer to them.

Some variables are
• $LINENO
• $DISPLAY
• $HOME
• $LOGNAME
• $MAIL
• $OLDPWD
• $PATH
• $PWD
• $SHELL
• $TERM
• $USER

These variables are always UPPER CASE

The way we use them is to prefix a dollar sign $ and use echo to print them to the screen like so:

2024-11-30 14:47:16
[~/httpd/bash] trudge: echo $LOGNAME
trudge
2024-11-30 14:50:08
[~/httpd/bash] trudge:

The $PATH variable becomes important when we run the various shell commands discussed in these pages. It tells the shell where to look for external commands.

If you get a message saying "command not found", it means the command you are trying to run is not in one of the directories in $PATH, or you may have spelled it wrong (case?).

Your PATH is adjustable by you - you can change the order of directories; add new ones; delete ones that are no longer needed.

This is where you would add the path to any external commands that you install yourself.

$LINENO

This one will become important once you get into scripting.

As you might imagine, it prints the current line number in the running script.

Why would you need to know this? This is a debugging and maintenance tool:

echo [$LINENO] Inserting tracks ...

If you see this in a possible script you are writing, you know the script has at least reached this line. Debugging begins with finding the place in your script that failed.


The prompt