Professional Documents
Culture Documents
In Linux single command do one thing and do it well
Complex command is a combination of single commands
You can make a new complex command by placing many single
commands in a file
The file itself is called a shell script
Shell script can be called as a single command
The name of a command is the name of the script file
$ chmod +x script_file_name
$ echo $SHELL
/bin/csh
To specify what shell you want your script to be executed, you need
to add
#!location_of_ shell
$ which shell_name
$ which sh
/bin/sh
#!/bin/sh
echo text_to_output
#/bin/sh
echo “Hello 9G”
$sh my_script
Hello 9G
VARIABLE_NAME=VALUE
To refer to variable value
$VARIABLE_NAME
MYVAR=”Hello 9”
echo “$MYVARGeneration”
If you want to specify a string follow a variable you must specified the
end of a variable
The end of a variable can be specified by using {}
MYVAR=”Hello 9”
echo “${MYVAR}Generation”
read VARIABLE_NAME
Please refer to “read.sh” for example
General Syntax
for filename in *
do
echo “$filename”
done
for i in 1 2 3 4 5 6 7 8 9 10
do
echo $i
done
max=10
for ((i=1; i <= max; i++))
do
echo $i
done
Nested Loop
for i in 1 2 3 4
do
for j in 1 2 3 4
do
echo “Row $i Column $j”
done
done
Syntax
if ( test condition)
then
command 1
command 2
.....
fi
Syntax
case word in
value1)
command ..
;;
value2)
command...
;;
*)
command ...
esac