NEWS: Total Picture Views: 151536 | Total Article Views: 161014 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. PickUpThings with Becker Robot | 3. How to read a JSON and work with it | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Script if file exist or not Bash

Description:

In this example I will be showing a script to verify if the file exist and if it's readable.

Code:

#!/bin/bash
echo "Enter filename: \c"
read filename
if [ -r $filename -a -s $filename ]
then
	echo "File $filename exists and is not empty."
	echo "You have read access permission to the file."
else
	echo "File $filename does not exist or is empty"
fi
exit 0
Attachments: None

Tags: read input variable

Total Views: 938

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 01/28/15


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.