Coding Knowledge Center
Bash
Arrays |
ARRAY=('item1' 'item2' 'item3');
item1 = $ARRAY[0];
item2 = $ARRAY[1];
item3 = $ARRAY[2];
Set an array with three items. Then set a separate variable to each array element's item name.
Do loop |
for i in `ls`;
do
echo $i
done
This will get a listing of the current directory and then echo its contents to the screen.
Environmental variable ($PS1 - command prompt) |
PS1='[\u(`id -gn`)@\h] \w% '
[steved(grouper)@blackbox] /home/steved% _
Sets the prompt accordingly:
\u = user
\h = hostname
\w = current working directory
`id -gn` = current group
Environmental variable ($TERM - terminal) |
TERM=vt100
> echo $TERM
vt100
Sets the current shells $TERM variable to vt100. To verify type echo $TERM.
Functions |
myfunc() {
...
param1 = $1;
param2 = $2;
param3 = $3;
function contents
...
}
myfunc ("item1" "item2" "item3");
Set function and get the parameters passed. Call function and pass in three parameters.