1

I am using arch and bash. Everything is up to date.

I have this command which works just fine

yad \
--timeout=2 \
--undecorated \
--posx=1200 --posy=633 \
--title=" " \
--window-icon='/home/$USER/.local/share/file-manager/spanner_white.png' \
--no-buttons \
--no-focus \
--text="All print jobs cancelled"; # This is a comment

Clearly I can make a comment after the ; at the end of the command as shown.

However is there a way I can make a comment after each \
It does not seem so, but may be I just don't know how.

If this can't be done with bash can it be done with zsh or any other shells.

Kusalananda
  • 333,661
Kes
  • 859

1 Answers1

4

No, the backslash at the end of a line acts on the next character, the newline character (removing it). If you add a space and a # character, the backslash will act on the space instead (quoting it), not the newline character. You also can't add a comment at the end of the line and then a backslash character, because the comment would effectively comment out the rest of the continued line.

What you could do is to create an array for the arguments, and comment the various parts of it as you do it, and then use that in a call to your utility:

yad_args=(
    # A timeout of 20 is used in testing; production uses 2.
    #--timeout=20
    --timeout=2
    --undecorated  # We don't want decorations.
    --posx=1200 --posy=633
    --title=" "   # Spacey title.
    --window-icon="${XDG_DATA_HOME:-$HOME/.local/share}"/file-manager/spanner_white.png
    --no-buttons
    --no-focus    # No focus for you!
    --text="All print jobs cancelled"
)

yad "${yad_args[@]}"

While declaring each element of the array yad_args, it's possible to add comments at the end of the lines.

Note that when using the array in the call to yad, the expansion must be quoted exactly as shown above, or you will have issues with array elements containing spaces and/or filename globbing characters.

Kusalananda
  • 333,661
  • This approach also allows you to comment out entire lines with arguments easily, which you can't do with continuation lines. – DonHolgo Sep 26 '23 at 10:16