簡體   English   中英

作為Shell腳本的一部分非交互式創建p4標簽時出錯

[英]Error in creating p4 label non-interactively as part of shell script

這是在我的shell腳本中創建p4標簽的代碼片段

for i in $( echo TEST-01); do
    p4 label -i << ENDOFLABEL
    Label: $i
    Options: unlocked

    Description: label from Automation

    View:
         //depot/...

    ENDOFLABEL
done

它引發如下錯誤; 怎么了?

warning: here-document at line 125 delimited by end-of-file (wanted `ENDOFLABEL')
./p4_l.sh: line 150: syntax error: unexpected end of file

這里文檔的結束標記必須左對齊。

for i in $( echo TEST-01); do
    p4 label -i << ENDOFLABEL
    Label: $i
    Options: unlocked

    Description: label from Automation

    View:
         //depot/...

ENDOFLABEL
done

或者,如果您使用實際的制表符進行縮進,則可以在開始標簽前面使用減號:

for i in $( echo TEST-01); do
    p4 label -i <<-ENDOFLABEL
    Label: $i
    Options: unlocked

    Description: label from Automation

    View:
         //depot/...

    ENDOFLABEL
done

空格將無效。 本文文檔中的所有前導標簽都將被刪除。 這解決了p4不喜歡Label:行之前的空格的問題。 還有其他方法可以解決此類問題。 一種是使用諸如X的字母來標記“真實數據”的起始位置:

    sed 's/^[[:space:]]*X//' <<-ENDOFLABEL | p4 label -i
    XLabel: $i
    XOptions: unlocked

    XDescription: label from Automation

    XView:
    X     //depot/...

    ENDOFLABEL
done

只有ENDOFLABEL行必須使用制表符縮進,如果需要,可以在//depot/行之前使用制表符。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM