Вы находитесь на странице: 1из 2

Shell Programming

chmod 775 file


./file
Let x=Hello Directly puts Hello as value of x
read x Waits for the value of x and puts the value in x
$0 The name of the command
$1, $2, $3 Command lines
Echo dollar 1 =
$0
$x Value of variable x
$# Number of parameters
$* #Whole set of values separated by space:
Sum=0
for num in $*
do
let sum=$sum+$num
done
echo $sum

echo Prints on screen


echo Hello Vargha
Hello Vargha and goes to a new line
echo -n No new line after print
echo e Recognize special characters like: \n in the text
Echo > instead of printing on screen, create/overwrites the output in
Vargha>text.txt the file
Echo >> appends to (adds to the end of) file
Vargha>>text.txt
: Comment Multiple Line Comment
#! Comment Single line comment
#!/usr/bin/bash NOTE: there is space after #!
fi Kind of Endif
While [expr] # inside shell, or inside a file:
do #!/usr/bin/bash
~~~~ X=0 #NoSpace
~~~~~ while [ $x lt 10 ]
done do
echo $x
let x=$x+1
done
word One word at a time (for example from a file): for word in $x
While read x
do Read the first line of file and put in in variable x
~~~~~
done < file
if [expr]
then
~~~~
~~~~~
elif [expr]
~~~~
~~~~~
else
~~~~
~~~~~
fi
For(;;) for ((i=0; i<10;i++))
do do
~~~~~ echo i=$i
done done
-eq Equal to if [ "$a" -eq "$b" ]
((==)) Equal to if (("$#"=="0"))
-ne NOT Equals if [ "$a" -ne "$b" ]
((!=)) NOT Equal to if (("$#"!="0"))
-ge Greater than or Equal to if [ "$a" -gt "$b" ]
-gt Greater than if [ "$a" -ge "$b" ]
-le Less than or Equal to if [ "$a" -le "$b" ]
-lt Less than [ "$a" -lt "$b" ]
Note: For strings: == or !=
-e if exist (in checking statements)
break Stops the loop
continue Goes to top of the loop
`` #Putting command between back quot in a variable
x=`ls`
Echo $x
`` #Another example:
d = grep `^d`
Arithmetic in Shell mid=$((high+low))
mid=$((((high+low))/2))

Own Grou Worl


Permissions: er p d

R: Read, W: 1/ 1/ 1/ Write, X: Search


0
RWX0 RWX
0 RWX

1: Permission, 0: No-Permission

Change Mode command: chmod 755 file1

Вам также может понравиться