码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2015-04-30 10:52:57      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:for

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


本文出自 “牧羊暗语” 博客,请务必保留此出处http://466716241.blog.51cto.com/1475798/1640762

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

标签:for

原文地址:http://466716241.blog.51cto.com/1475798/1640762

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!