Using file test - Part 1
#!/bin/bash
#filetest.sh
if [ -x "filetest.sh" ]
then
echo "filetest.sh is executable"
else
echo "filetest.sh is not executable"
fi
$ sh filetest.sh
filetest.sh is not executable
$ chmod +x filetest.sh
$ ./filetest.sh
filetest.sh is executable
Now time for something interesting ..let me find out the executable files inside my home directory using this.Well i dont like the find options.
cat filetest.sh
#!/bin/bash
if [ -d "$1" ]
then
:
else
echo "A directory expected"
exit 1;
fi
for myfile in $( find $1 )
do
if [ -x "$myfile" -a -f "$myfile" ]
then
echo "$myfile is executable"
fi
done
#filetest.sh
if [ -x "filetest.sh" ]
then
echo "filetest.sh is executable"
else
echo "filetest.sh is not executable"
fi
$ sh filetest.sh
filetest.sh is not executable
$ chmod +x filetest.sh
$ ./filetest.sh
filetest.sh is executable
Now time for something interesting ..let me find out the executable files inside my home directory using this.Well i dont like the find options.
cat filetest.sh
#!/bin/bash
if [ -d "$1" ]
then
:
else
echo "A directory expected"
exit 1;
fi
for myfile in $( find $1 )
do
if [ -x "$myfile" -a -f "$myfile" ]
then
echo "$myfile is executable"
fi
done
0 Comments:
Post a Comment
<< Home