Question

Here is the code snippet for creating a p4 label in my shell script

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

    Description: label from Automation

    View:
         //depot/...

    ENDOFLABEL
done

It throws error as below; what is wrong?

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

Solution

The end marker of the here document must be left justified.

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

    Description: label from Automation

    View:
         //depot/...

ENDOFLABEL
done

Or, if you use actual tabs for indentation, you can use a minus sign in front of the start label:

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

    Description: label from Automation

    View:
         //depot/...

    ENDOFLABEL
done

Spaces won't work. All leading tabs from the here document will be removed. This fixes the problem with p4 not liking spaces before lines such the Label: line. There are other ways to handle such problems. One is to use a letter such as X to mark where the 'real data' starts:

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

    XDescription: label from Automation

    XView:
    X     //depot/...

    ENDOFLABEL
done

Only the ENDOFLABEL line must be tab-indented, and you can have tabs before the //depot/ line if you need them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top