In bash script, how to assign output of a command to a variable while keeping tabs?

Hi, wondering if it's been asked before but didn't find matches from google. Basically I have this line:

myvar=$(echo -e "a\tb")

Now somehow the '\t' from the echo output gets replaced with white space and then stored in $myvar.

It creates a problem for me later to use tab as delimiter to do cut on $myvar. Anyway to keep the tabs?

The TAB is still there, you are just printing the variable in a wrong way.. Try this:

echo "$myvar"
1 Like

Gosh..I knew it's gonna be easy, but didn't think this easy :slight_smile: Thank you, and dumb me...:slight_smile: