使用 bash 互動式終端,輸出結果quote a符合'a'預期。bash -c 'quote a'但是在 shell 腳本中使用或參考不起作用,會給出錯誤bash: line 1: quote: command not found。quote 不是可執行檔案,我在 bash 內置參考中找不到引號,那么這個命令來自哪里?
.bashrc:
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
stty -ixon
#source $HOME/.config/xdgrc
#source $HOME/.config/aliasrc
PS1='\[\033[38;2;50;255;50m\]\u\[\033[0m\]@\[\033[38;2;255;70;70m\]\h\[\033[0m\]:\w\[\033[38;2;50;255;50m\]\$\[\033[0m\]> '
uj5u.com熱心網友回復:
quote是一個輔助函式/usr/share/bash-completion/bash_completion:
# This function shell-quotes the argument
quote()
{
local quoted=${1//\'/\'\\\'\'}
printf "'%s'" "$quoted"
}
我不會使用它,因為它僅在啟用完成時在互動式 shell 中可用。
如果要轉義腳本中的特殊字符,可以使用${var@Q}orprintf %q代替。
$ wendys="Where's the beef?"
$ echo "${wendys@Q}"
'Where'\''s the beef?'
$ printf '%q\n' "$wendys"
Where\'s\ the\ beef\?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/451830.html
上一篇:從txt檔案中的讀取行追加
