-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheredoc.cheat
More file actions
38 lines (31 loc) · 769 Bytes
/
heredoc.cheat
File metadata and controls
38 lines (31 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% bash,heredoc,pushou from https://linuxize.com/post/bash-heredoc/
# heredoc simple expand
cat << EOF
The current working directory is: $PWD
You are logged in as: $(whoami)
EOF
# heredoc do not expand parameter
cat << "EOF"
The current working directory is: $PWD
You are logged in as: $(whoami)
EOF
# heredoc keep indent safe
cat <<- "EOF"
The current working directory is: $PWD
You are logged in as: $(whoami)
EOF
# heredoc redirect to a file
cat << EOF > /tmp/file.txt
The current working directory is: $PWD
You are logged in as: $(whoami)
EOF
# heredoc sed
cat <<'EOF' | sed 's/l/e/g'
Hello
World
EOF
# heredoc ssh
ssh -T user@host.com << EOF
echo "The current local working directory is: $PWD"
echo "The current remote working directory is: \$PWD"
EOF