Shell variables are set using the form var=value. Note that there can't be any space around the = sign. Environment variables are supported by exporting shell variables.
bash$ echo $v bash$ v=12 bash$ echo $v 12 bash$ printenv v bash$ export v bash$ printenv v 12 bash$ bash bash$ echo $v 12 bash$ v=14 bash$ echo $v 14 bash$ printenv v 14 bash$ exit exit bash$ echo $v 12
We can do everything with if statements. The general form is shown below in the shell program. Additional tests on files are given following.
#!/bin/bash # Set some local (shell) variables v=12 if [ $v = 12 ]; then echo The variable is twelve else echo The variable is $v fi
if [ -op filename]; then expr fi
| op | Test |
|---|---|
| r | Readable? |
| w | Writable? |
| x | Executable? |
| e | Exists? |
| O | Is owner of? |
| f | Is plain file? |
| d | Is directory? |
| L | Is symbolic link? |
for var in list do statements done
For example, the script:
for n in 1 2 3 4; do echo $n done
produces
1 2 3 4