If you want a function to just show the output of a command, there's no need to capture the output and then echo
it again.
Just run svn status -uq
directly. The stdout will be output from the function call as well.
If you really need to use variables and echo
them, you need to quote the argument passed to echo
if you want the whitespace to be preserved: echo "$status"
.
The reason is that $status
will literally contain the following:
M * 764 update
Status against revision: 771
When you run echo $status
, echo
will be called like this:
echo M * 764 update \
Status against revision: 771
This is more than one parameter, since Bash splits arguments on whitespace (see $IFS
). echo
will print each argument, separated by one space, so while the rest of the line looks fine, the newline will – in essence – be collapsed to one space.
If you surround the argument with a quote, echo
will only see it as one argument and correctly output it again.
The Bash Wiki has a good read on quotes and lists a few reasons why you should always quote your variables apart from a few exceptions.
svn status -uq
instead ofecho
ing the output of$(svn status -uq)
?