I\'m in a bash crash course today.
This is a bash function that returns a value, via echo:
#!/bin/bash
get_hello_name() {
echo \'Hello $1!\'
}
msg=
The working code after following John1024's tips (note the newlines print in the "1" lines, but not the "4", because of the e option):
#!/bin/bash
a_function() {
echo -e "Hello\nworld\n 1"
echo "Hello"
echo "world"
echo "Hello\nworld 4"
}
echo -e "Hello\nworld\n 1"
echo "Hello"
echo "world"
echo "Hello\nworld 4"
x=$(a_function "x")
echo "x-no-quotes>"
echo $x #No new lines!
echo ""
echo "$x" #Yes new lines!
echo "
Output:
Hello
world
1
Hello
world
Hello\nworld 4
x-no-quotes>
Hello world 1 Hello world Hello\nworld 4
Hello
world
1
Hello
world
Hello\nworld 4