Consider the following bash script:
#!/bin/bash
function foo {
echo -n $1
echo $2
}
foo 'Testing... ' 'OK' # => Testing...OK
# Whitespace --^ ^
# Missing whitespace -----------------^
What happened to the trailing whitespace in the first argument? How can preserve it?
Answer
What happened to the trailing whitespace in the first argument?
The whitespace was included on the
echo
command line, but was discarded by the shell, the same as if you had typed:echo -n Testing...
^
|----- there is a space here
How can preserve it?
Quote your variables:
function foo {
echo -n "$1"
echo "$2"
}
No comments:
Post a Comment