parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing multiple flags in a single {} replacement


From: Alastair Andrew
Subject: Passing multiple flags in a single {} replacement
Date: Sun, 13 May 2012 16:48:17 +0100

Hi,

I've been trying to use parallel to pass arguments to a bash script. Some of my 
script's flags have dependencies, so I use a bash function to echo out just the 
valid combinations. The problem is that whilst the echo-ed function output 
contains multiple flags when it's passed to the script in the parallel command 
they are treated as a single argument. I assume I'm encountering something 
subtle to do with how parallel does quoting. I've read the QUOTING section of 
the man page and experimented with prepending -q and bash -c to my command but 
have been unable to get it working properly. I've made a simplified version of 
my actual setup to try and find a working solution.

My test script is a simple file that reports how many arguments were passed to 
it (highlighting that it treats the generate args as a single argument). 

My ./driver.sh file:
#!/bin/bash
echo "$0 called with $# args [$@]"
exit 0

And the script I'm using to call the ./driver.sh looks like:
#!/bin/bash

while getopts "d" opt; do
        case $opt in
        d)
                dryrun="--dry-run"
                ;;
        esac
done

function generate_flags {
        echo "-j halt"
        for i in {1..3}; do
                echo "-j restart -t $i"
        done
        return 0
}

function experiment-1 {
        echo "Calling $FUNCNAME"
        parallel $dryrun --nice 19 "cd $PWD; ./driver.sh -i 
./problems/prob{1}.txt -p {2} {3}" ::: {1..3} ::: single full :::: 
<(generate_flags)
}

function experiment-2 {
        echo "Calling $FUNCNAME"
        parallel $dryrun "cd $PWD; ./driver.sh -k {1} {2} -h {3}" ::: on off 
:::: <(generate_flags) ::: {0..4}
}

for x in experiment-1 experiment-2; do
        $x
done

exit 0

If you call it with the -d flag it'll run parallel in --dry-run mode echo-ing 
its proposed runs allowing you to see the addition backslashes in the generated 
arguments. Using --nice inflates the number backslashes too.           


reply via email to

[Prev in Thread] Current Thread [Next in Thread]