使用管道或重定向.sh Shell 脚本
源码
#!/usr/bin/env bash
# redirecting the for output to a file
for file in /home/tiandi/*
do
if [ -d "$file" ]
then
echo "$file is a directory"
else
echo "$file is a file"
fi
done > output.txt
# piping a loop to another command
for state in "North Dakota" Connecticut
do
echo "$state is next place to go"
done | sort
echo "This completes our travels"
内容与示例整理自 dunwu/linux-tutorial,遵循 CC BY-SA 4.0;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。