Variables Within the UNIX Shell - Language variables and some special cases
(Page 5 of 5 )
The default character settings are normally English, however the shell is also capable of "speaking" in French, Spanish, German and so on. To make the shell "speak" a certain language, you need to change the LANG environment variable first. For setting specific local settings like the time and date show method preferred, you need to change the numeric variables that start with the LC_ (LC_ALL, LC_TIME, LC_NUMERIC).
To see what languages can be set on your system, use the local command. This will list the available char sets that the LANG environment variable can take. This is also the primary variable that can determine the LC ones if these are not defined.
There are a couple of special variables in the UNIX shell. I will present them in the table below:
Variable Name | What it means |
$1,$2, #3, ... $n | These are the arguments list of a command or shell script The $1 will refer to the first argument the $2 to the second and etc |
$0 | The name of the shell scrip/program |
$* | Contains all the arguments in a single string |
$@ | Like the previous example, but now it creates a string list, and not a single string (useful to iterate through a list) |
$# | The number of arguments for a shell script/program |
$? | The result of the last executed program (0 means success, and any other number means failure) |
$$ | The identifier number of the running process (process id) |
$! | The process id of the last program started by the shell that runs (or ran) in the background |
For example, let there be the alfa.sh script. We start it with the command line:
./alfa.sh one two three last
The $1 is one, $2 is two, $3 is three, $4 is the last inside the script.
$0 is alfa.sh.
$* is "one two three last".
$@ is "one", "two", "three" ,"last".
$# is equal with four.
This will be all for today. As usual, I invite you to rate my article and ask for your questions in the blog if you have any. In my next article, I will cover concepts like stream direction, pipes, special devices and more. Therefore, make sure you do not miss it if you want to learn shell programming. Live With Passion!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |