Tuesday, 11 June 2013

shell script to accept a file name from user and check whether file has permission to write. If write permission is there then append to the file

Code:
echo Enter the file name
read fname
if [ -w $fname ]
then
   echo Type text to append. To stop press Ctrl D.
   cat >> $fname
else
   echo The file has no write permission
fi

Output:
[ty2011330@localhost ~]$ sh per.sh
Enter the file name
b2
The file has no write permission

[ty2011330@localhost ~]$ sh per.sh
Enter the file name
prime.sh
Type text to append. To stop press Ctrl D.

No comments:

Post a Comment