How do I split a string on a delimiter in Bash?

I have this string stored in a variable: IN=”[email protected];[email protected]” Now I would like to split the strings by ; delimiter so that I have: ADDR1=”[email protected]” ADDR2=”[email protected]” I don’t necessarily need the ADDR1 and ADDR2 variables. If they are elements of an array that’s even better. After suggestions from the answers below, I ended up with … Read more

Echo newline in Bash prints literal \n

In Bash, tried this: echo -e “Hello,\nWorld!” But it doesn’t print a newline, only \n. How can I make it print the newline? I’m using Ubuntu 11.04 (Natty Narwhal). 20 20 You could use printf instead: printf “hello\nworld\n” printf has more consistent behavior than echo. The behavior of echo varies greatly between different versions.

How to concatenate string variables in Bash

In PHP, strings are concatenated together as follows: $foo = “Hello”; $foo .= ” World”; Here, $foo becomes “Hello World”. How is this accomplished in Bash? 30 30 foo=”Hello” foo=”${foo} World” echo “${foo}” > Hello World In general to concatenate two variables you can just write them one after another: a=”Hello” b=’World’ c=”${a} ${b}” echo … Read more