Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the command:

cm1 cm2 arg1 arg2 'argument 3'

It first goes to cm1, which will then redirect arg1 arg2 'argument 3' to another file.


#! /bin/bash
# some script here
cm2 $@


echo $#
# This returns 4 in lieu of 3 because the white space in 'argument 3' causes the argument to be split into two arguments.

So, how can I pass arguments from one script to another and make sure white space won't be read as an argument separator?

share|improve this question
up vote 2 down vote accepted

I assume you have to re-wrap it into quotes, like so:

#! /bin/bash
# some script here
cm2 "$@"
share|improve this answer
Thanks! It works on the simple example I gave. Now on the real script I am coding and that has more complex rerouting, arguments get broken at some point. But that means the error is coming from somewhere else... Thanks! – François ッ Vespa ت Mar 13 '12 at 10:30
It may be that you split these args later based on default IFS which default value is "<space><tab><newline>" – Cougar Mar 14 '12 at 9:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .