【shell 指令碼】刪除 由windows傳入linux含有的 ^M

楊奇龍發表於2011-03-16
#!/bin/bash
function usage(){
echo "Usage: `basename $0 ` source_file  new_file "
exit 0
}

[ $# != 2 ] && usage
cat $1 | tr -d "\r" > $2
chmod 755 $2
exit 0
=========測試==========
"varify_ture.sh" [converted][dos] 119L, 2611C written                                              
root@client.example.com ~/yang # ./varify_ture.sh  
: command not foundine 2:
: command not foundine 6:
: command not foundine 7: echo
: command not foundine 8:
Testing "0"
./varify_ture.sh: line 15: syntax error near unexpected token `fi'
./varify_ture.sh: line 15: `fi            # 0 Ϊ'
===================================
root@client.example.com ~/yang # ./dropblank.sh varify_ture1.sh  varif_2.sh
root@client.example.com ~/yang # ./varif_2.sh

Testing "0"
0 is true.

Testing "1"
1 is true.

Testing "-1"
-1 is true.

Testing "NULL"
NULL is false.

Testing "xyz"
Random string is true.

Testing "$xyz"
Uninitialized variable is false.

Testing "-n $xyz"
Uninitialized variable is false.

Testing "-n $xyz"
Null variable is false.

Testing "false"
"false" is true.

Testing "$false"
"$false" is false.

root@client.example.com ~/yang #

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-689620/,如需轉載,請註明出處,否則將追究法律責任。

相關文章