Note that there are some explanatory texts on larger screens.

plurals
  1. POBash parse & concatenate arguments for executing python
    primarykey
    data
    text
    <p>I've got a bootstrap (bash) that should filter out some arguments before it starts the propper python script.</p> <p>The problem is that whenever i pass a string with spaces into the bootstrap it gets mangled up once it arrives at python</p> <p>e.g executing</p> <pre><code>./myBootStrap.sh --preload "argl bargl" -j -as -argl --postload "my Test" </code></pre> <p>prints this</p> <pre><code>Executing myBootStrap --preload "argl bargl" -j -as -argl --postload "my Test" </code></pre> <p>and my python script prints its argument </p> <pre><code>got arguments ['myBootStrap','--preload', '"argl', 'bargl"', '-j', '-as', '-argl', '--postload', '"my', 'Test"'] </code></pre> <p>as you see the "argl bargl" and "my Test" get split up into ['"argl','bargl"'] &amp; ['"my', 'Test"'] instead of staying combined.</p> <p>any idea whats wrong with my code ?</p> <p>thanks heaps!</p> <hr> <p>myBootStrap.sh</p> <pre><code>#!/bin/bash declare -a argv for ((i=1;i&lt;=${#@};i+=1)) do arg=${@:i:1} if [[ "$arg" == "--preload"* ]];then i=$i+1 marg=${@:$((i)):1} preLoadO=$arg preLoadA=" \"${marg}\"" argv=("${argv[@]}" $arg) argv=("${argv[@]}" $preLoadA) elif [[ "$arg" == "--postload"* ]];then i=$i+1 marg=${@:$((i)):1} postLoadO=$arg postLoadA=" \"${marg}\"" argv=("${argv[@]}" $arg) argv=("${argv[@]}" $postLoadA) else argv=("${argv[@]}" $arg) fi done arguments=$(printf " %s" "${argv[@]}") arguments=${arguments:1} echo "Executing myBootStrap" $arguments exec myBootStrap $arguments </code></pre> <p>and the python script myBootStrap</p> <pre><code>#!/usr/bin/env python import sys print 'got arguments %s'%sys.argv </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload