天天看點

shell中感歎号與引号用法

線上環境需要定期清理緩存,如下:

[root@LB scripts]# curl http://10.238.74.31/irm/manualDataSyncPage!synchronizeCrmGroupCustomerInfo.html?UserName=004&Password=ZHzg-123   

-bash: !synchronizeCrmGroupCustomerInfo.html?UserName=004: event not found

  “!”在日常指令中可以作為調用history曆史記錄來使用執行某行内容,在shell裡為特殊字元。

在執行curl "http://10.238.74.31/irm/manualDataSyncPage!synchronizeCrmGroupCustomerInfo.html?UserName=004&Password=ZHzg-123"的過程中,發現“!”無法被正常解析,加上轉義反斜杠“\”也沒用。

-bash: !event not found

   後發現在“!”前後加入空格可以解決這個問題,但還不夠完美,因為輸入的檔案字元也是加了空格後的,感覺占用較長地方,現象如下:

[root@LB scripts]# curl "http://10.238.74.31/irm/manualDataSyncPage ! synchronizeCrmGroupCustomerInfo.htmlme=004&Password=ZHzg-123"

   最後嘗試雙引号與反斜杠同時使用,完美解決問題!具體如下:

[root@LB scripts]# curl "http://10.238.74.31/irm/manualDataSyncPage"\!"syncronizeCrmGroupCustomerInfo.html?UserName=004&Password=ZHzg-123" 

<html>

<head>

<title>system.title</title>

<script>

var hexA0s = unescape(' %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0 %A0');

hexA0s = hexA0s + hexA0s + hexA0s + hexA0s;

document.title = 'system.title' + hexA0s + hexA0s;

hexA0s = null;

</script>

<meta http-equiv="Pragma" Content="No-cach"></meta>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>

本文轉自 linuxzkq 51CTO部落格,原文連結:http://blog.51cto.com/linuxzkq/1827401