Article 5BW9S How to check execution permission of files in a given directory?

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.
Thankslatest?d=yIl2AUoC8zA latest?i=THCCZXRrZfQ:-Qb8NhvHpn4:F7zBnMy latest?i=THCCZXRrZfQ:-Qb8NhvHpn4:V_sGLiP latest?d=qj6IDK7rITs latest?i=THCCZXRrZfQ:-Qb8NhvHpn4:gIN9vFwTHCCZXRrZfQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments