Tutorial by Examples

You can indent the text inside here documents with tabs, you need to use the <<- redirection operator instead of <<: $ cat <<- EOF This is some content indented with tabs `\t`. You cannot indent with spaces you __have__ to use tabs. Bash will remove empty space befo...
2.05b You can feed a command using here strings like this: $ awk '{print $2}' <<< "hello world - how are you?" world $ awk '{print $1}' <<< "hello how are you > she is fine" hello she You can also feed a while loop with a here string: $ while IFS...
A heredoc uses the limitstring to determine when to stop consuming input. The terminating limitstring must Be at the start of a line. Be the only text on the line Note: If you use <<- the limitstring can be prefixed with tabs \t Correct: cat <<limitstring line 1 line 2 limit...
A classic use of here documents is to create a file by typing its content: cat > fruits.txt << EOF apple orange lemon EOF The here-document is the lines between the << EOF and EOF. This here document becomes the input of the cat command. The cat command simply outputs its in...
ssh -p 21 [email protected] <<EOF echo 'printing pwd' echo "\$(pwd)" ls -a find '*.txt' EOF $ is escaped because we do not want it to be expanded by the current shell i.e $(pwd) is to be executed on the remote shell. Another way: ssh -p 21 [email protected] <...
sudo -s <<EOF a='var' echo 'Running serveral commands with sudo' mktemp -d echo "\$a" EOF $a needs to be escaped to prevent it to be expanded by the current shell Or sudo -s <<'EOF' a='var' echo 'Running serveral commands with sudo' mktemp -d e...

Page 1 of 1