如何将bash脚本拆分成命令?

时间:2017-06-18 04:23:16

标签: bash parsing

例如我可以通过EOL将这个bash脚本拆分为命令:

echo "1"
pwd
cd ../

但是如何拆分更复杂的bash脚本如下?

if [ $# -lt 1 ]
then
  echo "Usage: $0 file ..."
  exit 1
fi

echo "$0 counts the lines of code" 
l=0; n=0; s=0
for f in $*
do
    l=`wc -l $f | sed 's/^\([0-9]*\).*$/\1/'`
    echo "$f: $l"
        n=$[ $n + 1 ]
        s=$[ $s + $l ]
done

echo "$n files in total, with $s lines in total"

0 个答案:

没有答案