There are many paths to the system variables included in path under each Linux path:
root@wl-ms-7673:/home/wl/Desktop/shell# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/ Usr/games:/usr/local/arm/4.5.1/bin
root@wl-ms-7673:/home/wl/Desktop/shell#
If you want to count the number of files under each path in path, first extract each path under the path, you must replace the colon with a space:
root@wl-ms-7673:~# echo $PATH | Sed ' s/://g '
/usr/local/sbin/usr/local/bin/usr/sbin/usr/bin/sbin/bin/usr/games/usr/local/arm/4.5.1/bin
Once you have separated the directory, you can traverse each directory in the standard for statement:
For directory in $mypath
Todo
..............
Done
The complete code is as follows:
root@wl-ms-7673:/home/wl/Desktop/shell# cat-n conutfiles.sh
1 mypath= ' echo $PATH | sed ' s/://g '
2 count= 0
3 for directory in $mypath
4 does
5 check= ' ls $directory '
6 for item in $check
7 do
8 count=$[$count + 1]
9 done by echo "$directory-$count"
11 count=0
root@wl-ms-7673:/home/wl/Desktop/shell#
The results of the operation are as follows:
root@wl-ms-7673:/home/wl/desktop/shell#./conutfiles.sh
/usr/local/sbin-0
/usr/local/bin-0
/usr/sbin-
/usr/bin-1870
/sbin-182
/bin-152
/usr/games-4
/usr/local/arm/4.5.1/bin-48