0

I have two variables and I have to append the value of both variable into a 3rd variable by giving 4 spaces in between the variable.

for eg:

$ a="a"
$ b="b"
$ echo $a"     "$b

output:

a    b

when I am doing

$ c=$(echo $a"    "$b)
$ echo $c

output:

a b

Required output:

a    b
avinashse
  • 1,440
  • 4
  • 30
  • 55

1 Answers1

1

Just say:

c="$a    $b"

This will set $c as $a + 4 spaces + $b.

To see it working, use echo or printf using double quotes so that the format is kept:

$ c="$a    $b"
$ echo "$c"
a    b

Note, also, that when you say:

$ c=$($a"    "$b)

You will get the error:

bash: a b: command not found

Because you are using var=$(command) syntax, which stores in $var the output of the command command. However, the command you are trying to run is $a" "$b, that is, a b, which is not a command.

fedorqui
  • 275,237
  • 103
  • 548
  • 598