Search code examples
batch-filecygwin

How to include pipe character in an argument to a batch file from a bash script?


I have a shell script that I want to execute this line:

qtvars.bat vsstart "qt.sln" /BUILD "Debug|Win32"

This works fine (though I had to modify qtvars.bat, but that's beside the point). The problem is that I want the command to execute to be in a variable: EDIT: This doesn't work either, if I type it into bash. Previously I was typing it into cmd.exe, which hardly made for a fair comparison.

command="qtvars.bat"
args="vsstart"

$command $args "qt.sln" /BUILD "Debug|Win32"

Now it chokes on the pipe! I get this message:

'Win32' is not recognized as an internal or external command,
operable program or batch file.

I've tried a bunch of forms of escaping the quotes and/or pipe, all to no avail. Interestingly, it works when it's an executable rather than a batch file, e.g.:

command="devenv.exe"
args=""

$command $args "qt.sln" /BUILD "Debug|Win32"

Thanks for any ideas.


Solution

  • I know you "escape" the pipe character in a batch file with the ^ character, so...

    echo ^| Some text here ^|
    

    Would display...

    | Some text here |
    

    I don't know whether that would help you in this instance? Maybe try prepending each pipe character with a ^ and see what happens? :-)