bashubuntubatch-filecmdwindows-subsystem-for-linux

Is it possible to make a .bat Bash hybrid?


In cmd, it is possible to use Linux commands with the ubuntu or bash commands, but they are very fickle. In batch, it is also possible to make a VBScript-batch hybrid, which got me thinking, is it possible to make a Bash-batch hybrid? Besides being a tongue-twister, I feel that Bash-batch scripts may be really useful.


What I have tried so far

What I want this for relates to my other question where I am trying to hash a string instead of a file in cmd, and you could do it with a Bash command, but I would still like to keep the file as a batch file.


Solution

  • Sure you can use Bash in batch, assuming it is available. Just use the command bash -c 'cmd', where cmd is the command that you want to run in Bash.

    The following batch line pipes the Hello to cat -A command that prints it including the invisible symbols:

    echo Hello | bash -c "cat -A"
    

    Compare the output with the result of the version completely written in Bash:

    bash -c "echo Hello | cat -A"
    

    They will slightly differ!