${varname:-word}
5 Depeche Mode
2 Split Enz
3 Simple Minds
1 Vivaldi, Antonio
#!/bin/sh
sort -nr $1 | head -${2:-10}
groad@linux-z13e:~/shell> sh test.sh test.txt
5 Depeche Mode
3 Simple Minds
2 Split Enz
1 Vivaldi, Antonio
groad@linux-z13e:~/shell>sh test.sh test.txt 5
5 Depeche Mode
3 Simple Minds
2 Split Enz
1 Vivaldi, Antonio
#!/bin/sh
filename=$1
howmany=${2:-10}
sort -nr $filename| head -$howmany
#!/bin/sh
filename=${1:?"filename missing."}
howmany=${2:-10}
sort -nr $filename| head -$howmany
test.sh: line 3: 1: filename missing.
#!/bin/sh
filename=${1:?"filename missing."}
howmany=$2
sort -nr $filename| head -${howmany:=2}
groad@linux-z13e:~/shell> sh test.sh test.txt
5 Depeche Mode
3 Simple Minds
#!/bin/sh
header=""
filename=${1:?"filename missing."}
howmany=$2
if [ “$3” == "-header" ];then
header=$3
fi
echo-e -n ${header:+"ALBUMS ARTIST\n"}
sort -nr $filename| head -${howmany:=2}
groad@linux-z13e:~/shell> sh test.sh test.txt 3 -heade
5 Depeche Mode
3 Simple Minds
2 Split Enz
groad@linux-z13e:~/shell> sh test.sh test.txt 3 -header
ALBUMS ARTIST
5 Depeche Mode
3 Simple Minds
2 Split Enz
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |