Control Instructions in Shell-9
Control Instructions in Shell-9
Simple if Example-
#ss13
echo enter source and target file names
read source target
If cp $source $target
then
echo File copied successfully
fi
Exercise Question-
File Tests-
We have a few operators that can be used to test various properties associated with a Unix file.Assume
a variable file holds an existing file name "test" the size of which is 100 bytes and has read, write and
execute permission on –
-e file exists
-a file exists This is identical in effect to -e. It has been "deprecated," [1] and its use is discouraged.
-dfile is a directory
Q2—Shell script- To check whether the user has write permission to the file.If Yes then append
something into the file.
String Test
str1="Good"
str2="Bad"
str3=
[$str1 = $str2 ]
echo $?
[$str1 != $str2 ]
echo $?
[ -n $str1 ]
echo $?
[-z "$str3" ]
echo $?
[-z $str3 ]
echo $?
["$str3"]
echo $?
Str1=”Good Morning”
Str2=”Good Bye”
[“$str1”=”$str2”]
Echo $?
(Since str1 and str2 are having two words , so we need to enclose them in double quotes)