Created
February 7, 2018 20:49
-
-
Save tuxmartin/e1f141b14d18717b94b8a1806695afd8 to your computer and use it in GitHub Desktop.
Here Documents & Here Strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LAN_IP="192.168.1.1" | |
LAN_MASK="255.255.255.0" | |
LAN_GW="192.168.1.254" | |
echo "hello world" | wc -w | |
wc -w <<< "hello world" | |
grep "dev" <<<`ls -1 /` >/dev/null && echo "Found" || echo "Not found" | |
grep "windows" <<<`ls -1 /` >/dev/null && echo "Found" || echo "Not found" | |
cat << EOF > /tmp/a | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
EOF | |
# je potreba escapovat, co se nema dosadit/vyhodnotit | |
cat << EOF > /tmp/b | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
dns-nameservers \$LAN_GW | |
EOF | |
# 'EOF' - apostrof zajisti nenahrazovani promennych | |
cat << 'EOF' > /tmp/c | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
EOF | |
# <<- pomlcka dovoli cely oblok odsadit od zacatku radku, jinak musi byt EOF na prvnim sloupci | |
cat <<- 'EOF' > /tmp/d | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
EOF | |
cat <<- EOF > /tmp/e | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
EOF | |
cat <<- KonecTextu > /tmp/f | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
KonecTextu | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
martin@martin:/tmp$ ./here_string.sh | |
2 | |
2 | |
Found | |
Not found | |
martin@martin:/tmp$ cat a | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address 192.168.1.1 | |
netmask 255.255.255.0 | |
gateway 192.168.1.254 | |
martin@martin:/tmp$ | |
martin@martin:/tmp$ cat b | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address 192.168.1.1 | |
netmask 255.255.255.0 | |
gateway 192.168.1.254 | |
dns-nameservers $LAN_GW | |
martin@martin:/tmp$ | |
martin@martin:/tmp$ cat c | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
martin@martin:/tmp$ | |
martin@martin:/tmp$ cat d | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $LAN_IP | |
netmask $LAN_MASK | |
gateway $LAN_GW | |
martin@martin:/tmp$ | |
martin@martin:/tmp$ cat e | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address 192.168.1.1 | |
netmask 255.255.255.0 | |
gateway 192.168.1.254 | |
martin@martin:/tmp$ | |
martin@martin:/tmp$ cat f | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address 192.168.1.1 | |
netmask 255.255.255.0 | |
gateway 192.168.1.254 | |
martin@martin:/tmp$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment