How to check execution permission of files in a given directory?
by was123 from LinuxQuestions.org on (#5BW9S)
Hi Everybody,
I am new to linux Environment, i wrote a script to check execution permission of files in a given directory(it could be anywhere) but i am having a little trouble.
my files are in /home/ec2-user/practice directory.
and i am running below script from /home/ec2-user directory.
cmd: ./scriptname /home/ec2-user/practice
#!/usr/bin/env bash
path=$1
for each in $(ls $path)
do
if [[ -x $each ]]
then
echo "$each has execution permission"
else
echo "$each does not have execution permission"
fi
done
O/P
for all the files i am getting output as "does not have execution permission" although some files has execution permission.
but if i pass specific file name as command line arguments its working like ./scriptname /home/ec2-user/practice/xyz.sh
Would appreciate your support.
Thanks


I am new to linux Environment, i wrote a script to check execution permission of files in a given directory(it could be anywhere) but i am having a little trouble.
my files are in /home/ec2-user/practice directory.
and i am running below script from /home/ec2-user directory.
cmd: ./scriptname /home/ec2-user/practice
#!/usr/bin/env bash
path=$1
for each in $(ls $path)
do
if [[ -x $each ]]
then
echo "$each has execution permission"
else
echo "$each does not have execution permission"
fi
done
O/P
for all the files i am getting output as "does not have execution permission" although some files has execution permission.
but if i pass specific file name as command line arguments its working like ./scriptname /home/ec2-user/practice/xyz.sh
Would appreciate your support.
Thanks