我有以下(部分)shell腳本(內部t7508-status.sh):
test_expect_success 'status --column' '
cat >expect <<\EOF &&
# On branch main
# Your branch and '\''upstream'\'' have diverged,
# and have 1 and 2 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
# (use "git restore --staged <file>..." to unstage)
# new file: dir2/added
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git restore <file>..." to discard changes in working directory)
# modified: dir1/modified
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# dir1/untracked dir2/untracked
# dir2/modified untracked
#
EOF
COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output &&
test_cmp expect output
'
好的,第一個參考的部分似乎很明顯status --column,但是第二個參考的部分從第一行的末尾開始,恕我直言,在第三行結束
# Your branch and '\''upstream'\'' have diverged,
^--here
然后一個轉義的參考后面跟著一個新的參考部分?還是<<\EOF ... EOF優先級更高?我提出問題的原因是使用 ANTLR 創建正確的語法著色。
uj5u.com熱心網友回復:
你是對的:第一個參考的部分在第三行結束,緊接著是一個轉義的單引號,然后是另一個單引號部分。然后同樣的事情在 8 個字符之后再次發生。由于這些部分之間沒有空格或其他分隔符,因此它們被視為單個長字串的一部分( 的引數test_expect_success)。
由于<<\EOFand#標記出現在單引號部分中,它們根本沒有語法意義;它們只是文字字符,將test_expect_success作為引數的一部分傳遞給。在單引號字串中,唯一具有任何語法意義的東西是單引號(它只是表示單引號部分的結尾)。
您可以通過將test_expect_success命令替換為 來查看結果printf '[%s]\n',并查看[ ]標記內列印的內容。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/407713.html
標籤:
上一篇:連接兩個都有重復行的檔案
