Search code examples
linuxshellprintfcomments

How do I put comment on each line in bash for printf?


I have the following code in my Dockerfile. Then I piped the output to my setup.py. I need to run this command in linux terminal. How can i put comment on each line?

  printf "%s\n" \
    # Facebook OAuth Client ID (default)
    "1234" \
    # Facebook OAuth Secret (default)
    "abcd" \
    # Google OAuth Client ID (default)
    "5678" \
    # Google OAuth Secret (default)
    "qwer" \

Solution

  • Using arrays in order to avoid long escaped by \ lists of arguments is a good practice. You can leave a comment for each element.

    CREDENTIALS=(
        # Facebook OAuth Client ID (default)
        "1234"
        # Facebook OAuth Secret (default)
        "abcd"
        # Google OAuth Client ID (default)
        "5678"
        # Google OAuth Secret (default)
        "qwer"
    )
    printf "%s\n" "${CREDENTIALS[@]}"