Search code examples
lsf

how to handle quotes and semicolon in bsub command


I'm trying to submit commands to the LSF scheduler with bsub but this command includes a parameter value that must be quoted and contains a semicolon.

Here is a simple command to illustrate my problem

bsub -o t.o -e t.e echo "foo;bar"

it fails with "line 8: bar: command not found", so I thought I could escape the semicolon but this

bsub -o t.o -e t.e echo "foo\;bar"

causes the same error, so does this

bsub -o t.o -e t.e echo 'foo;bar'

I know I can get around it by writing the command to a script file and executing that as the bsub command but in this case I am going to test a number of parameters and it would be so much handier to just modify the bsub command rather than editing a shell script each time.

Thanks for your help!


Solution

  • One simple way I can think of to do this is to use bsub's subshell interface: simply execute bsub <options> from your command line without specifying a command. bsub will then prompt you for a command in a subshell, and you can use quotes in this subshell.

    Send the subshell an end-of-file (CTRL+D) to let it know you're done. Here's an example run using something similar to your case but running interactively instead of using -o to capture the output:

    %  bsub -I
    bsub> echo "foo;bar"
    bsub>       <================[### Hit CTRL+D here ###]
    Job <5841> is submitted to default queue <normal>.
    <<Waiting for dispatch ...>>
    <<Starting on hb05b10>>
    foo;bar
    %