1

I have 2 variable :$table and $i

table=test
i=1

when i try to separate these two variables with tab with the below command:

echo "$table\t$i\tSuccess" > success.txt

The output is

 test\ti

The desired output is

test    1

Appreciate valuable suggestions.

keeplearning
  • 369
  • 2
  • 6
  • 17

2 Answers2

5

Use printf:

printf "%s\t%s\tSuccess\n" "$table" "$i" > success.txt

or echo -e (the -e flag enables interpretation of the backslash-escaped characters):

 echo -e "$table\t$i\tSuccess" > success.txt
Inian
  • 80,270
  • 14
  • 142
  • 161
William Pursell
  • 204,365
  • 48
  • 270
  • 300
1

You can write a tab in Bash as $'\t'.

What I do in my scripts is create a constant. The tab itself is not special: once you have it in a variable, you can use it the normal way.

readonly tab=$'\t'
echo "$table$tab$i${tab}Success" > success.txt
Fred
  • 6,590
  • 9
  • 20