To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.
the “end-of-file” (EOF) key combination can be used to quickly log out of any terminal. CTRL-D is also used in programs such as “at” to signal that you have finished typing your commands (the EOF command). CTRL-Z. key combination is used to stop a process. It can be used to put something in the background temporarily.
The EOF operator is used in many programming languages. This operator stands for the end of the file. This means that wherever a compiler or an interpreter encounters this operator, it will receive an indication that the file it was reading has ended.
EOT is an ASCII character that historically signalled the end of a message (and is a special character in UNIX terminals that means end of stream when it appears in user input only), but it CAN appear in files, so using it in C to signal the end of a file would be a terrible idea when reading binary files!
Remove the backslash before EOF
:
#!/bin/bash
i=ok
# This prints "Bwah ok"
cat <<EOF
Bwah $i
EOF
# This prints "Bwah $i"
cat <<\EOF
Bwah $i
EOF
To get your last line display rightsubnet="10.109.0.20/32"
(for i=1), you need something like this:
i=1
val1=beep
val2=bop
rightval="val$i"
cat <<EOF
This is a beep: ${!rightval}
EOF
That is, you compute the name of the variable you want, put that in another variable, and use the ${!var}
syntax.
But for that kind of thing you should rather use an array:
i=0
vals=(beep bop)
cat <<EOF
This is a beep: ${vals[$i]}
EOF
Note however that the indexes start at 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With