shell脚本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


你可能感兴趣的:(shell,脚本,for)