Question:
Open a file and read the content and print the lines one by one, also check the file is exist or not if it is absent say file is absent
Answer:
#!/usr/bin/bash
path="/home/kalam/filename.sh"
if [ -e $path ]
then
echo "File is exists in the following path: $path"
for line in $(cat "$path")
do
echo "line: $line"
done
else
echo "file is absent"
echo "Please provide realpath of the file and re-run the script"
echo "Thank you for using this script"
exit 1
fi
No comments:
Post a Comment