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

21 lines
359 B
Bash
Raw Normal View History

2019-10-29 18:22:19 +08:00
#!/usr/bin/env bash
2019-05-10 11:17:57 +08:00
# redirecting the for output to a file
for file in /home/tiandi/*
do
2019-10-29 18:22:19 +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-29 18:22:19 +08:00
echo "$state is next place to go"
2019-05-10 11:17:57 +08:00
done | sort
echo "This completes our travels"