Reputation: 1805
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
Upvotes: 5
Views: 5821
Reputation: 361556
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"
Upvotes: 12