linux-tutorial/codes/shell/示例脚本/逻辑控制/使用管道或重定向.sh

21 lines
378 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# redirecting the for output to a file
for file in /home/tiandi/*
do
2019-10-10 08:56:31 +08:00
if [ -d "$file" ]
then
echo "$file is a directory"
else
echo "$file is a file"
fi
2019-05-10 11:17:57 +08:00
done > output.txt
# piping a loop to another command
for state in "North Dakota" Connecticut
do
2019-10-10 08:56:31 +08:00
echo "$state is next place to go"
2019-05-10 11:17:57 +08:00
done | sort
echo "This completes our travels"