I want to string concatenation two given strings line1 and line2 and entering a newline between them. Any idea please?
I tried the following but it didn't work:
enter='\n'
lines=$line1$enter$line2
Use $'...'
to have the shell interpret escape sequences.
enter=$'\n'
lines=$line1$enter$line2
You can also put a newline directly inside double quotes:
lines="$line1
$line2"
Or use printf
:
printf -v lines '%s\n%s' "$line1" "$line2"
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