-1

I have to count all executable files- done it and count files which are .sh files- no idea how to do it. Any help? Here's my code:

c=0 d=0 for f in /home/lenovo/*; do if [ -x "$f" ] ; then c=$(($c+1)) if $f . name -iname = '*.sh'; then d=$(($d+1)) fi fi done echo $c echo $d 
0

2 Answers 2

1

With a correct find command, you can do a correct and quick way to do this, for example :

find . -type f -name "*.sh"|wc -l 

And you can set more arguements in find to be more efficient (for example -maxdepth -mindepth or -ctime or -executable or -perm that could be intersting too in you use case)

Sign up to request clarification or add additional context in comments.

Comments

0

Could it be as simple as ls /home/lenovo/*.sh | wc -c? Or do you have other requirements?

This would count any file ending with .'sh' whether it is executable or not.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.