With Bash, you can append to a variable, example
$ foo=Hello
$ foo+=world
$ echo $foo
Helloworld
However, is this possible with the read
command? Something like
$ foo=Hello
$ read --append foo
world
$ echo $foo
Helloworld
Not directly, so use a temp variable.
foo="Hello"
read tmp
foo+="$tmp"
You can fake it, kind of, using readline
:
$ foo=Hello
$ read -e -i"$foo" foo
Hello
When using readline
via the -e
flag, the argument to -i
is put on the first line of the input to get you started. You're not so much appending to foo
as giving foo
a whole new value, which just happens to begin with the old value if you don't edit the initial line.
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