天天看點

計算shell指令個數

-d 目前路徑是否是目錄

-x 此檔案是否可以執行

#!/bin/bash

IFS=":"
count=0 ; nonex=0

for directory in $PATH ; do
  if [ -d "$directory" ] ; then
    for command in "$directory"/* ; do
      if [ -x "$command" ] ; then
        count="$(( $count + 1 ))"
      else
        nonex="$(( $nonex + 1 ))"
      fi
    done
  fi
done

echo "$count 個指令, $nonex 不可以執行的"

exit 0