I have never been a fan of programming or scripting. Thought is was a skill I was unable to learn. When learning to administer a Linux system, scripting can not be avoided.
One of the skills every sysAdmin must learn is scripting. The benefit of scripting is to automate a task or job that is constantly run every time a system is running. A sysAdmin can make that job run on its own and concentrate on other tasks that are not so easily automated. These scripts are either written using a text editor, the shell, or, scripting language.
I was not automating anything, just getting used to writing scripts. When I was studying "Linux essentials" in preparation for the Linux certification, I was practicing passing variable values. That is, printing the value of one of my system's default variables. I had a crazy thought. What if I actually ran a script using a variable. I soon learned, Linux is what you make of it.
There are default variables already set on a Linux system. To find what these variables are, you simply type this command in a shell or terminal emulator, “printenv”
This is a screen shot of the default variables on my Linux Mint 17 system.
Take a close look at the bold text above. These are my custom variables I set to run some custom scripts.
OPENDVD=eject /dev/sr0 is used to open my laptop's DVD disc drive.
PLAYMEDIA=vlc /dev/sr0 is used to play a DVD using VLC.
Of course I could have just written the scripts using a text editor. I wanted to make things more interesting by try something different. Also, doing this helped me learn and appreciate environmental variables much more. I find them really fun to play with.
Always remember this syntax, "command argument". The command is what you want to run, the argument is what you want it to run on. The command “VLC” opens the VLC media player program. The argument “/dev/sr0” is the DVD disc drive I want it to open. Typing this in your terminal will do just that.
If you look at the subfolder “etc”, you will notice a file named “environment”. You can actually use this filie to create and store your own custom declared variables. On some Ubuntu based systems, you might noticed the default “PATH” variable is also located there. A little F.Y.I.
Once you set your desired variable, and save the file, restart your system. Run the “printenv” command and you will see your variables listed.
To set a variable, type in all caps, the name of the variable, then after that, the “=” sign and then the value that the variable will relate to. Like this, VARIABLE=value. In my case I typed, OPENDVD=”eject /dev/sr0”. The quotes surrounding the command indicates that the command should be treated as one value.
Once this is written, I had reset my mint system. Once logged in, and the terminal was opened, I called the value of the new variable. This is when you tell your terminal to print the value of a variable. The command to do this is, prompt<$VARIABLENAME>.When I typed, “$OPENDVD”, my dvd disc drive opens. Your system will recognize a variable when it starts with a dollar sign followed by a name in all caps as in, "$OPENDVD".
I was not big on programming. Yet, scripting, using variables, not only makes Linux even more interesting but programming as well. I already have a large list of scripts I want to experiment with. When I think about it, scripting might actually be my thing. I went beyond just learning what a variable is. I begun learning how to talk to Linux using my own language.