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
If I understand your problem correctly (which I’m not sure about; see my comment), you should probably add another
\nto yourprintf;printfdoes not add a trailing newline by default the way thatechodoes. This will ensure that the second value will be read properly by theselectcommand which I’m assuming appears inexport_map.sh.Also, I don’t think that you need to add the
/bin/bash -cand quote marks. The following should be sufficient, unless I’m missing something: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$1is 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.Here’s a quick example of how
"$@"works. First,inner.bash:outer.bash:And invoking it: