tags:

views:

40

answers:

4

Hi everybody,

I'm rather new to bash, and somehow just haven't found out what I'm doing wrong here: (this is a small bash script calling my generator)

    if [ -n $folder ]; then
        $zorbalocation -q $generator -f -e files=\"$lFiles\" -e folder=\"lFolder\"
    else
        $zorbalocation -q $generator -f -e files=\"$lFiles\" -e folder=\".\"
    fi

Now, obviously I want bash to execute these commands, depending on the content of folder. But, for some reason, bash insists on putting apostrophes ( ' ) around files=... and folder =... So, it tries to execute

../../../zorba/build/bin/zorba -q generator.xq -f -e 'files="test.xqlib"' -e 'folder="."'

instead of

../../../zorba/build/bin/zorba -q generator.xq -f -e files="test.xqlib" -e folder="."

Does anybody know why bash insists on inserting the apostrophes there?

A nice day to everyone

Danny

A: 

As long as they need no further interpretation (e.g. variable expansion), putting single quotes around arguments or command name should not be a problem for bash.

mouviciel
The problem is, that I am trying to call a program with this command, and bash is putting the single quotes around files=\"$lFiles\"which is passed as argument to the called program, which won't take this argument if it has single quotes around it.
What error do you get?
mouviciel
Well, the error is specific to the program (zorba) that I'm calling, which would like to be calledzorba -q file.xq -f -e files="..." -e folder="..."but, for inexplicable reasons, bash callszorba -q file.xq -f -e 'files="..."' -e 'folder="..."which makes zorba not recognize the arguments properly ...(I'm using set -x to see what is really called)
The source of the problem may lie in zorba itself and in its way to read command line arguments.
mouviciel
Not really, when running the script with set -x, I see that bash calls + '[' -n ']' + ../../../zorba/build/bin/zorba -q generator.xq -f -e 'files="test.xqlib"' -e 'folder="."'This is just the wrong way to call zorba, as it expects it's command line arguments not to have quotes around them (meaning the single quotes around files="..." and folder="..."
A: 

put echo in your statement and see if they are what you expect. Also, try not to escape those double quotes.

if [ -n $folder ]; then
    echo $zorbalocation -q $generator -f -e files="$lFiles" -e folder="lFolder"
else
    echo $zorbalocation -q $generator -f -e files="$lFiles" -e folder="."
fi

otherwise, show the rest of your code before executing this portion

ghostdog74
Well, there isn't really a lot of stuff beforehand actually just the variable used in the command are filled appropriately, and what is really baffling is that with echo the apostrophes aren't added, but when I leave it as command they are ...If I leave out the escaping of the double quoutes, then they just don't appear in the command ... (I'm using set -x to see what is really executed).
+1  A: 

Bash doesn't add ' to the command that is executed. You only see the quote when running your script with bash -x or set -x; then bash tries to print out the commands it runs, and to be helpful, it quotes tokens that would need quoting if you wanted to paste them back into bash, therefore a="b" becomes 'a="b"'. Your issue must be something else.

Kilian Foth
Thanks a lot Killian Foth, this helps greatly, at least I now know where the problem surely isn't.
A: 

Everything cleared now, it seems that by using the eval command everything works fine. Thanks to all here for your help.