0

There are two bash scripts in the directory:

foo.sh

#!/usr/bin/env bash

./bar.sh $@

bar.sh

#!/usr/bin/env bash

echo $#

When I run ./foo.sh 1 " ", get 1 instead of 2. So " " argument is ignored when passed to ./bar.sh.

How can I pass " " to ./bar.sh?

Jingguo Yao
  • 7,320
  • 6
  • 50
  • 63
  • 2
    The answer is almost always "use quotes". Read the answers (plural) to [When to wrap quotes around a variable](http://stackoverflow.com/q/10067266/258523) for some discussion and examples of this. – Etan Reisner Mar 24 '16 at 12:37

1 Answers1

4

Just use "$@" that preserves white space and even empty arguments.

kamikaze
  • 1,529
  • 8
  • 18