[英]Double quotation mark escaping in alias
我正在嘗試在Debian Stretch中設置以下別名
alias myalias='watch -d -n 0.1 '\''find /path -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c'\'''
我試圖用'\\'來轉義第一組引號,但它不適用於較深的引號
%TY-%Tm-%Td\n
運行命令時,最終得到以下輸出。 %TY-%Tm-%Td \\ n周圍的引號不再存在,輸出不解釋\\ n並且結果在一行上。
Every 0.1s: find /root/bolero/bolero/pkl/stocks -type f -printf %TY-%Tm-%Td\n | sort | uniq -c
有什么想法可以使這項工作嗎?
您正在尋找的輸出是這樣的:
alias myalias='watch -d -n 0.1 '\''find /path -type f -printf '\''\'\'''\''%TY-%Tm-%Td\n'\''\'\'''\'' | sort | uniq -c'\'''
當然,這非常復雜。
因為沒有人想計算引號,所以讓我向您介紹您可能不了解的Git功能: git rev-parse --sq-quote
。 如果您想知道如何將文本正確地單引號,請將該部分雙引號,然后將其傳遞給git rev-parse --sq-quote
。 因此,它看起來像這樣:
$ git rev-parse --sq-quote "find /path -type f -printf '%TY-%Tm-%Td\n' | sort | uniq -c"
'find /path -type f -printf '\''%TY-%Tm-%Td\n'\'' | sort | uniq -c'
$ git rev-parse --sq-quote "watch -d -n 0.1 'find /path -type f -printf '\''%TY-%Tm-%Td\n'\'' | sort | uniq -c'"
'watch -d -n 0.1 '\''find /path -type f -printf '\''\'\'''\''%TY-%Tm-%Td\n'\''\'\'''\'' | sort | uniq -c'\'''
這就是您獲得結果的方式。 請注意,Git會在行上插入一個前導空格,您可能需要將其刪除以保持整潔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.