Search code examples
echo

echo multi-line string to a file


How can I create a .gitignore file and add:

/node_modules
.DS_Store
.env

all in one command line?

I know I can do this: echo ".DS_Store" >> .gitignore


Solution

  • The classic way to do this is using a HEREDOC (see man bash)

    cat - <<EOF >> .gitignore
    /nodemodules
    .DS_Store
    .env
    EOF