作業六: low pass and high pass filter with sh
•建立二個 shell 執行檔, 名為 less-than, greater-than
•每個執行檔會用到第一個參數當作 bound
•從 stdin 每一行讀一個數字, 滿足條件則印出到 stdout,
$ cat numbers
19
23
101
55
34
$ cat numbers | ./less-than 60
19
23
55
34
$ cat numbers | ./less-than 60 | ./greater-than 30
55
34
$
解答:
#-----less-then-----
#!/bin/sh
while read number
do
if [ $1 -gt $number ]; then
echo $number
fi
done
#-----greater-then-----
#!/bin/sh
while read number
do
if [ $number -gt $1 ]; then
echo $number
fi
done
執行結果: