但他们都有地方有一个额外的错误报价。
我只是以这种方式运行一个简单的 awk 脚本:
awk -f test.awk -v time="$t" copy.out
现在当我输入直到
awk -f test.awk -v time="$t" c #Press Tab after c
并按 Tab 完成选项卡我收到错误:
awk -f test.awk -v time="$t" cbash: unexpected EOF while looking for matching `"'
bash: syntax error: unexpected end of file
我的命令中有适当数量的双引号。我肯定知道这一点,因为如果我在没有制表符完成的情况下输入我的文件名然后执行命令,那么它工作正常。
我错过了什么?
当我运行bash -x
然后执行上述步骤时,我得到:
word split
+ _init_completion -s
+ local exclude= flag outx errx inx OPTIND=1
+ getopts n:e:o:i:s flag -s
+ case $flag in
+ split=false
+ exclude+==
+ getopts n:e:o:i:s flag -s
+ COMPREPLY=()
+ local 'redir=@(?([0-9])<|?([0-9&])>?(>)|>&)'
+ _get_comp_words_by_ref -n '=<>&' cur prev words cword
+ local exclude flag i OPTIND=1
+ words=()
+ local cur cword words
+ upargs=()
+ upvars=()
+ local upargs upvars vcur vcword vprev vwords
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ case $flag in
+ exclude='=<>&'
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ [[ 6 -ge 3 ]]
+ case ${!OPTIND} in
+ vcur=cur
+ let 'OPTIND += 1'
+ [[ 6 -ge 4 ]]
+ case ${!OPTIND} in
+ vprev=prev
+ let 'OPTIND += 1'
+ [[ 6 -ge 5 ]]
+ case ${!OPTIND} in
+ vwords=words
+ let 'OPTIND += 1'
+ [[ 6 -ge 6 ]]
+ case ${!OPTIND} in
+ vcword=cword
+ let 'OPTIND += 1'
+ [[ 6 -ge 7 ]]
+ __get_cword_at_cursor_by_ref '=<>&' words cword cur
+ words=()
+ local cword words
+ __reassemble_comp_words_by_ref '=<>&' words cword
+ local exclude i j line ref
+ [[ -n =<>& ]]
+ exclude='=<>&'
+ printf -v cword %s 6
+ [[ -n =<>& ]]
+ line='awk -f test.awk -v time="$t" c'
+ (( i=0, j=0 ))
+ (( i < 7 ))
+ [[ 0 -gt 0 ]]
+ ref='words[0]'
+ printf -v 'words[0]' %s awk
+ line=' -f test.awk -v time="$t" c'
+ [[ 0 == 6 ]]
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 1 -gt 0 ]]
+ [[ -f == +([=<>&]) ]]
+ ref='words[1]'
+ printf -v 'words[1]' %s -f
+ line=' test.awk -v time="$t" c'
+ [[ 1 == 6 ]]
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 2 -gt 0 ]]
+ [[ test.awk == +([=<>&]) ]]
+ ref='words[2]'
+ printf -v 'words[2]' %s test.awk
+ line=' -v time="$t" c'
+ [[ 2 == 6 ]]
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 3 -gt 0 ]]
+ [[ -v == +([=<>&]) ]]
+ ref='words[3]'
+ printf -v 'words[3]' %s -v
+ line=' time="$t" c'
+ [[ 3 == 6 ]]
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 4 -gt 0 ]]
+ [[ time == +([=<>&]) ]]
+ ref='words[4]'
+ printf -v 'words[4]' %s time
+ line='="$t" c'
+ [[ 4 == 6 ]]
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 5 -gt 0 ]]
+ [[ =" == +([=<>&]) ]]
+ ref='words[5]'
+ printf -v 'words[5]' %s '="'
+ line='$t" c'
+ [[ 5 == 6 ]]
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 6 -gt 0 ]]
+ [[ $t" c == +([=<>&]) ]]
+ ref='words[6]'
+ printf -v 'words[6]' %s '$t" c'
+ line=
+ [[ 6 == 6 ]]
+ printf -v cword %s 6
+ (( i++, j++ ))
+ (( i < 7 ))
+ [[ 7 == 6 ]]
+ local i cur index=30 'lead=awk -f test.awk -v time="$t" c'
+ [[ 30 -gt 0 ]]
+ [[ -n awk -f test.awk -v time="$t" c ]]
+ [[ -n awk-ftest.awk-vtime="$t"c ]]
+ cur='awk -f test.awk -v time="$t" c'
+ (( i = 0 ))
+ (( i <= cword ))
+ [[ 30 -ge 3 ]]
+ [[ awk != \a\w\k ]]
+ [[ 0 -lt 6 ]]
+ local old_size=30
+ cur=' -f test.awk -v time="$t" c'
+ local new_size=27
+ index=27
+ (( ++i ))
+ (( i <= cword ))
+ [[ 27 -ge 2 ]]
+ [[ - != \-\f ]]
+ cur='-f test.awk -v time="$t" c'
+ [[ 27 -gt 0 ]]
+ (( index-- ))
+ [[ 26 -ge 2 ]]
+ [[ -f != \-\f ]]
+ [[ 1 -lt 6 ]]
+ local old_size=26
+ cur=' test.awk -v time="$t" c'
+ local new_size=24
+ index=24
+ (( ++i ))
+ (( i <= cword ))
+ [[ 24 -ge 8 ]]
+ [[ test.aw != \t\e\s\t\.\a\w\k ]]
+ cur='test.awk -v time="$t" c'
+ [[ 24 -gt 0 ]]
+ (( index-- ))
+ [[ 23 -ge 8 ]]
+ [[ test.awk != \t\e\s\t\.\a\w\k ]]
+ [[ 2 -lt 6 ]]
+ local old_size=23
+ cur=' -v time="$t" c'
+ local new_size=15
+ index=15
+ (( ++i ))
+ (( i <= cword ))
+ [[ 15 -ge 2 ]]
+ [[ - != \-\v ]]
+ cur='-v time="$t" c'
+ [[ 15 -gt 0 ]]
+ (( index-- ))
+ [[ 14 -ge 2 ]]
+ [[ -v != \-\v ]]
+ [[ 3 -lt 6 ]]
+ local old_size=14
+ cur=' time="$t" c'
+ local new_size=12
+ index=12
+ (( ++i ))
+ (( i <= cword ))
+ [[ 12 -ge 4 ]]
+ [[ tim != \t\i\m\e ]]
+ cur='time="$t" c'
+ [[ 12 -gt 0 ]]
+ (( index-- ))
+ [[ 11 -ge 4 ]]
+ [[ time != \t\i\m\e ]]
+ [[ 4 -lt 6 ]]
+ local old_size=11
+ cur='="$t" c'
+ local new_size=7
+ index=7
+ (( ++i ))
+ (( i <= cword ))
+ [[ 7 -ge 2 ]]
+ [[ =" != \=\" ]]
+ [[ 5 -lt 6 ]]
+ local old_size=7
+ cur='$t" c'
+ local new_size=5
+ index=5
+ (( ++i ))
+ (( i <= cword ))
+ [[ 5 -ge 5 ]]
+ [[ $t" c != \$\t\"\ \c ]]
+ [[ 6 -lt 6 ]]
+ (( ++i ))
+ (( i <= cword ))
+ [[ -n $t" c ]]
+ [[ ! -n $t"c ]]
+ [[ 5 -lt 0 ]]
+ local words cword cur
+ _upvars -a7 words awk -f test.awk -v time '="' '$t" c' -v cword 6 -v cur '$t" c'
+ (( 15 ))
+ (( 15 ))
+ case $1 in
+ [[ -n 7 ]]
+ printf %d 7
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:7}")'
++ words=("${@:3:7}")
+ shift 9
+ (( 6 ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=6
+ shift 3
+ (( 3 ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur='$t" c'
+ shift 3
+ (( 0 ))
+ [[ -n cur ]]
+ upvars+=("$vcur")
+ upargs+=(-v $vcur "$cur")
+ [[ -n cword ]]
+ upvars+=("$vcword")
+ upargs+=(-v $vcword "$cword")
+ [[ -n prev ]]
+ [[ 6 -ge 1 ]]
+ upvars+=("$vprev")
+ upargs+=(-v $vprev "${words[cword - 1]}")
+ [[ -n words ]]
+ upvars+=("$vwords")
+ upargs+=(-a${#words[@]} $vwords "${words[@]}")
+ (( 4 ))
+ local cur cword prev words
+ _upvars -v cur '$t" c' -v cword 6 -v prev '="' -a7 words awk -f test.awk -v time '="' '$t" c'
+ (( 18 ))
+ (( 18 ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur='$t" c'
+ shift 3
+ (( 15 ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=6
+ shift 3
+ (( 12 ))
+ case $1 in
+ [[ -n prev ]]
+ unset -v prev
+ eval 'prev="$3"'
++ prev='="'
+ shift 3
+ (( 9 ))
+ case $1 in
+ [[ -n 7 ]]
+ printf %d 7
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:7}")'
++ words=("${@:3:7}")
+ shift 9
+ (( 0 ))
+ _variables
+ [[ $t" c =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]
+ [[ $t" c =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]]
+ [[ $t" c =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*]$ ]]
+ case $prev in
+ return 1
+ [[ $t" c == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ [[ =" == @(?([0-9])<|?([0-9&])>?(>)|>&) ]]
+ local i skip
+ (( i=1 ))
+ (( i < 7 ))
+ [[ -f == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=2
+ (( 1 ))
+ (( i < 7 ))
+ [[ test.awk == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=3
+ (( 1 ))
+ (( i < 7 ))
+ [[ -v == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=4
+ (( 1 ))
+ (( i < 7 ))
+ [[ time == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=5
+ (( 1 ))
+ (( i < 7 ))
+ [[ =" == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=6
+ (( 1 ))
+ (( i < 7 ))
+ [[ $t" c == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=7
+ (( 1 ))
+ (( i < 7 ))
+ [[ 6 -le 0 ]]
+ prev='="'
+ [[ -n false ]]
+ _split_longopt
+ [[ $t" c == --?*=* ]]
+ return 1
+ return 0
+ case "${prev,,}" in
+ false
+ [[ $t" c == -* ]]
+ [[ awk == @(rmdir|chroot) ]]
+ [[ awk == mkdir ]]
+ _filedir
+ local 'IFS=
'
+ _tilde '$t" c'
+ local result=0
+ [[ $t" c == \~* ]]
+ return 0
+ local -a toks
+ local x tmp
++ compgen -d -- '$t" c'
+ x=
+ [[ '' != -d ]]
+ local quoted
+ _quote_readline_by_ref '$t" c' quoted
+ '[' -z '$t" c' ']'
+ [[ $t" c == \'* ]]
+ [[ $t" c == \~* ]]
+ printf -v quoted %q '$t" c'
+ [[ \$t\"\ c == *\\* ]]
+ printf -v quoted %s '$t" c'
+ [[ $t" c == \$* ]]
+ eval 'quoted=$t" c'
bash: unexpected EOF while looking for matching `"'
bash: syntax error: unexpected end of file
+ local xspec=
++ compgen -f -X '' -- '$t" c'
+ x=
+ [[ -n '' ]]
+ [[ 0 -ne 0 ]]
它说的最后几行,unquoted $t"
但我确实提供了完整的引号并且它确实有效。那么这不是某种错误吗?我的意思是 bash 冒昧地忽略或错误地解析了我的起始报价
从您的
bash -x
输出中,您在 bash-completion 包中发现了一个错误(它不是 的一部分bash
,而是由社区维护的选项卡完成包)。您的问题是在这种情况下运行的 bash 完成在传递给时无法正确转义引用eval
:查看错误跟踪器,这看起来是这个错误,它已在上游修复,但补丁尚未进入您的存储库。
你有几个选择: