My understanding is that echo '$var'
will print as a literal $var
because the single quotes suppression the variable expansion.
[user1@server1 ~]$ var1=a
[user1@server1 ~]$ echo '$var1'
$var1
[user1@server1 ~]$ echo $var1
a
[user1@server1 ~]$
Now I saw a script:
#!/bin/bash
# read-multiple: read multiple values from keyboard
echo -n "Enter one or more values > "
read var1 var2 var3 var4 var5
echo "var1 = '$var1'"
echo "var2 = '$var2'"
echo "var3 = '$var3'"
echo "var4 = '$var4'"
echo "var5 = '$var5'"
Why is the value of the variables not being suppressed here?
[user1@server1 ~]$ ./read1.sh
Enter one or more values > a b c d e
var1 = 'a'
var2 = 'b'
var3 = 'c'
var4 = 'd'
var5 = 'e'
'
is just a normal character: it does not quote anything else. Specifically, it does not quote the expansion. – Paul_Pedant Apr 16 '22 at 21:51