#Author: Surendra Anne(surendra at linuxnix.com)
#Purpose: To check if a file exit's or not.
read -p "Please enter a file name with full path"
if [ -f $REPLY ]
echo "The file $REPLY exists"
echo "File not found"
We have [ inbuilt command which will do file/folder checking with. So -f is used to check if a file exit's or not.
Save the file as chkfile1.sh and exit it.
Execute the script
Step1:change permissions to execute permissions as below
chmod +x chkfile1.sh
Step2: Executing shell script
Please comment your thoughts on this.
Latest posts by Surendra Anne (see all)
- FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018
- wget download a file to a directory in Linux/Unix - June 4, 2018
- GIT: How to compare two GIT branches? - June 3, 2018