221
edits
Changes
no edit summary
<code>alias clearfile=”cat /dev/null >”</code>
Shell variables a classified in 2 groups:
Variables can be read/write or read-only. Name of a variable can be any sequence of letters and numbers, but it must not start with a number.
Shell environment variables shape the working environment whenever you are logged in. Common shell variables include:
The <code>set</code> command will display all available variables
* <code>PATH</code> is an environment variable present in Unix/Linux operating systems, listing directories where executable programs are located
* Use <code>./</code> prefix or modify the <code>PATH</code> as needed
Syntax: <code>name=value</code>
</source>
* Including the keyword <code>readonly</code> before the command assignment prevents you from changing the variable afterwards. For example: <code>readonly phone=“123-4567”</code>
* If no variable name is supplied a list of defined read only variables will be displayed
<code>variable=</code>
Read-only variables cannot be removed, you must log out for them to be cleared.
Whenever you wish to read a variable (its contents), use the variable name preceded by a dollar sign ($). This is commonly called ''variable substitution''.
* <code>$#</code> represents the number of parameters (not including the script name)
== <code>echo</code> command ==
* Displays messages to the terminal followed by a newline. Use the <code>-n</code> option to suppress the default newline.
* Arguments are usually double quoted.
== <code>read</code> command ==
* The <code>read</code> command allows obtaining user input and storing it in a variable. Everything is captured until the Enter key is pressed.
echo Hello $name
</source>
== Using Logic ==
The purpose of the if statement is execute a command or commands based on a condition. The condition is evaluated by a test command, represented below by a pair of square brackets
</source>
== <code>test</code> Command ==
The <code>test</code> command can be used in two ways:
Check <code>man test</code> for more details
== Using Loops ==
A for loop is a very effective way to repeat the same command(s) for several arguments such as file names. The syntax and example of for command is shown below: