📄 redir4.sh
字号:
#!/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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -