您的位置:首页 > 运维架构 > Shell

shell脚本for实用(不定期更新)

2015-04-30 10:17 246 查看
1、实现sourse目录下部分文件(文件名以文本列表形式列出,文本文件名为list),复制到另外一个目录/opt/targe/下
#!/bin/bash
cd /opt/source
for file in `cat /opt/source/list` ;
do
cp -r -n $file /opt/targe/
done
注:``在tab键上面 ,cp -n代表不覆盖。
扩展 scp -P 端口号 root@ip:/opt/source/ /opt/targe/

2、
#!/bin/bash
for str in 1 2 3 4 5
do
echo -e "The value is: $str \n"
done
输出
The value is: 1

The value is: 2

The value is: 3

The value is: 4

The value is: 5
#!/bin/bash
for str in "1 2 3 4 5"
do
echo -e "The value is: $str \n"
done
输出
The value is: 1 2 3 4 5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  脚本 shell for