代码改变世界

shell 常用1

2013-01-09 12:56  brookin  阅读(165)  评论(0编辑  收藏  举报

字符串切割

str="abcdefg"
#字符串切割
echo ${abc:0:3}
#输出abc

 

文件分发

scp.exp

#!/usr/bin/expect

if {$argc<4} {
    puts stderr "Usage: ./scp.exp \[SRC_FILE\] \[DST_IP\] \[DST_DIR\] \[PASSWORD\]"
    exit 1
}

set SRC_FILE    [lindex $argv 0]
set IP          [lindex $argv 1]
set DEST_DIR    [lindex $argv 2]
set PASSWORD    [lindex $argv 3]

spawn /usr/local/bin/scp -P 36000 $SRC_FILE user_00@$IP:$DEST_DIR
expect "*assword:"
send $PASSWORD"\r"
expect eof

 

屏蔽dos2unix输出

dos2unix /tmp/file.txt >/dev/null 2>&1

 

 echo 不含换行符

[user_00@txyun ~]$ echo "00003f30e2ffd363e798f03b61bbcf00" | wc
      1       1      33
[user_00@txyun ~]$ echo -n "00003f30e2ffd363e798f03b61bbcf00" | wc
      0       1      32

echo Description:

-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)