0
$ c=$(./getnumbers -n 5)
$ echo $c
1 2 3 4 5
$ ./getnumbers -n 5
1
2
3
4
5

How do I get it to store inside the variable as a column and not a row?

1 Answers1

1

The output is stored "as a column", i.e. with the \n between lines preserved:

$ c=$(./getnumbers -n 5)
$ echo $c
1 2 3 4 5
$ echo "$c"
1
2
3
4
5

Without the " quotes, what is happening is that the shell is passing the output lines to echo as individual arguments. echo in turn then does its job and outputs them all - with only a space between them. With the " quotes, $c is passed to echo without being interpreted by the shell, so echo is then able to output the value correctly, as it was captured.