#filename is "highest" filename=$1 filename=${filename:?"missing."} howmany=$2 sort -nr $filename | head -${howmany:=10} echo "$howmany books have been selected"
filename中的输入文件中myflie的内容是
#filename is myfile 5 Depeche Mode 2 Split Enz 3 Simple Minds 1 Vivaldi, Antonio
输入
./highest myfile 3
返回内容为
5 Depeche Mode 3 Simple Minds 2 Split Enz 3 books have been selected
我设想是如果输入的是
./highest myfile
返回内容应该是
5 Depeche Mode 3 Simple Minds 2 Split Enz 1 Vivaldi, Antonio 10 books have been selected
但是实际上返回的是
5 Depeche Mode 3 Simple Minds 2 Split Enz 1 Vivaldi, Antonio books have been selected
也就是说 sort -nr $filename | head -${howmany:=10} 执行完之后 $howmany 依然是null而不是10。