Question2:
Write a script whether the file is readable or not, if it is readable print the file content on the terminal after 5 sec
Answer:
Path="/home/kalam/filename.sh"
echo "User provide path is : $Path"
sleep 5
if [ -e $Path ]
then
echo "file is present in the $Path"
if [ -r $Path ]
then
echo "the file $Path is readable"
info=$(cat $Path)
echo $info
else
echo "file is not in readable format"
fi
else
echo "File is absent in the given path: $Path"
echo "Please correct the path and rerun the script"
echo "thank you for using this script"
fi
Output:
User provide path is : /home/kalam/filename.sh
file is present in the /home/kalam/filename.sh
the file /home/kalam/filename.sh is readable
echo "Please Provide the user name and state name" read name state_name echo "User provided name is :$name and His state name is : $state_name " if [ "$state_name" = "andra" ]; then echo "$name speaks Telugu" else echo "$name does not speak Telugu" fi
Note:
-r flag is used check for readable the file or not if yes condition will execute
No comments:
Post a Comment