0

I have a bash scripts which an argument enclosed with double quotes, which creates a shape-file of map within the given boundries, e.g.

$ export_map "0 0 100 100"

Within the script, there are two select statements:

select ENCODING in UTF8 WIN1252 WIN1255 ISO-8859-8;
...
select NAV_SELECT in Included Excluded;

Naturally, these two statements require the input to enter a number as an input. This can by bypassed by piping the numbers, followed by a newline, to the script.

In order to save time, I would like to have a script that would create 8 maps - for each combination of ENCODING (4 options) and NAV_SELECT (2 options).

I have written another bash script, create_map, to server as a wrapper:

#!/bin/bash

for nav in 1 2 3 4;
do
    for enc in 1 2;
    do
        printf "$nav\n$enc\n" | /bin/bash -c "./export_map.sh \"0 0 100 100\"" 
    done
done

**This works (thanks, Brian!), but I can't find a way to have the numeric argument "0 0 100 100" being passed from outside the outer script. **

Basically, I'm looking for way to accept an argument within double quotes to a wrapper bash script, and pass it - with the double quotes - to an inner script.

CLARIFICATIONS:

export_map is the main script, being called from create_map 8 times.

Any ideas?

Thanks,

Adam

Community
  • 1
  • 1
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
  • I'm a little unclear on what you are trying to do here. You say you're trying to do something with `select` statements, but there are no select statements in your bash script. You are printing out two numbers on different lines, and piping that into an invocation of your `export_map.sh` script, which you don't provide the code for (is it the same as the `create_map` you mention earlier?). I'm a bit unclear on where your quoting problems are coming in too. Can you try and elaborate on what exactly you are trying to do, and the exact problem you are having? – Brian Campbell Jan 03 '10 at 14:26
  • I have clarified my answer - thanks a bunch. – Adam Matan Jan 03 '10 at 14:49

1 Answers1

6

If I understand your problem correctly (which I'm not sure about; see my comment), you should probably add another \n to your printf; printf does not add a trailing newline by default the way that echo does. This will ensure that the second value will be read properly by the select command which I'm assuming appears in export_map.sh.

printf "$nav\n$enc\n" | /bin/bash -c "./export_map.sh \"100 200 300 400\""

Also, I don't think that you need to add the /bin/bash -c and quote marks. The following should be sufficient, unless I'm missing something:

printf "$nav\n$enc\n" | ./export_map.sh "100 200 300 400"

edit Thanks for the clarification. In order to pass an argument from your wrapper script, into the inner script, keeping it as a single argument, you can pass in "$1", where the quotes indicate that you want to keep this grouped as one argument, and $1 is the first parameter to your wrapper script. If you want to pass all parameters from your outer script in to your inner script, each being kept as a single parameter, you can use "$@" instead.

#!/bin/bash

for nav in 1 2 3 4;
do
    for enc in 1 2;
    do
        printf "$nav\n$enc\n" | ./export_map.sh "$1"
    done
done

Here's a quick example of how "$@" works. First, inner.bash:

#!/bin/bash

for str in "$@"
do
    echo $str
done

outer.bash:

#!/bin/bash

./inner.bash "$@"

And invoking it:

$ ./outer.bash "foo bar" baz "quux zot"
foo bar
baz
quux zot
Brian Campbell
  • 322,767
  • 57
  • 360
  • 340