redir4.sh
来自「Shall高级编程」· Shell 代码 · 共 33 行
SH
33 行
#!/bin/bashif [ -z "$1" ]then Filename=names.data # Default, if no filename specified.else Filename=$1fi line_count=`wc $Filename | awk '{ print $1 }'`# Number of lines in target file.## Very contrived and kludgy, nevertheless shows that#+ it's possible to redirect stdin within a "for" loop...#+ if you're clever enough.## More concise is line_count=$(wc -l < "$Filename")for name in `seq $line_count` # Recall that "seq" prints sequence of numbers.# while [ "$name" != Smith ] -- more complicated than a "while" loop --do read name # Reads from $Filename, rather than stdin. echo $name if [ "$name" = Smith ] # Need all this extra baggage here. then break fi done <"$Filename" # Redirects stdin to file $Filename. # ^^^^^^^^^^^^exit 0
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?