Skip to content

Instantly share code, notes, and snippets.

@jimathyp
Last active June 13, 2021 03:22
Show Gist options
  • Select an option

  • Save jimathyp/a6355a7afa3c7cbdeb51a6ee6d09168b to your computer and use it in GitHub Desktop.

Select an option

Save jimathyp/a6355a7afa3c7cbdeb51a6ee6d09168b to your computer and use it in GitHub Desktop.

Echo in bash

"$v" prevents pathname expansion or globbing and field splitting

parameter expansion need to use single quoting '$v' or escaping $v

single quotes prevent shell expansion

or for some expansion, use "$var $anothervar"

alos "${v}"

heredocs

https://en.wikipedia.org/wiki/Here_document

cat << EOF

asdasd EOF

EOF can be any indicator

<< vs <<- with -, in POSIZ shell, leading tabs are ignored, which has the effect of removing whitepsace in the output

output to file

$ cat << EOF > ~/testFile001

3 spaces precede this text. A single tab character is at the beginning of this line. Nothing precedes this text EOF

here string

$ LANG=C tr a-z A-Z <<< one ONE

https://linuxize.com/post/bash-heredoc/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment