1

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 vbs-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

  • So far I tried using the empty bash and ubuntu commands alone since they switch the normal command-prompt to ubuntu/bash shell, but even if you put commands after the ubuntu/bash they wouldn't show or do anyting.
  • After I tried that I tried using the ubuntu -run command but like I said earlier, its really fickle and inconsistent on what things work and what things don't. It is less inconsistent when you pipe things into it, but still usually doesn't work.
  • I looked here since it seemed like it would answer my question and I tried it but it didn't work since it required another program (I think).
  • Also looked to this and I guess it failled miserably, but interesting concept.
  • What I've gotten from all of my research is that most people think when this is mentioned of a file that could be run either as a .bat file or as .sh shell file instead of my goal, to make a file that runs both batch and bash commands in the same instance.

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.

Nico Nekoru
  • 2,402
  • 1
  • 15
  • 32
  • I would assume it would be very dependent upon the purpose, i.e. the commands to be used etc. Instead of asking a very generic question therefore, have you got a specific on topic actual issue you're trying to resolve, or have you asked a general programming question here instead of a more suitable platform. That said, **have you seen [this question](https://stackoverflow.com/q/17510688) and answers?** – Compo May 14 '20 at 17:03
  • I saw it, see point 5. "What I've gotten from all of my research is that most people think when this is mentioned of a file that could be run either as a .bat file or as .sh shell file instead of my goal, to make a file that runs both batch and bash commands in the same instance." – Nico Nekoru May 14 '20 at 17:04
  • Well surely you certainly didn't link that question or answers, so how was I supposed to make a correlation. Ypu could, depending upon the wsl version you're using, prepend your 'nix commands with `wsl` as you normally would, and if necessary, do that within a [tag:for-loop], if you need the output in such a way as direct printing or piping isn't possible! As I say, your question isn't really valid for this site, this is for helping with a specific coding issue, you're looking for general programming suggestions and opinion, which is not the purpose of StackOverflow. – Compo May 14 '20 at 17:11
  • So there is no possible way to accomplish a true hybrid bash batch script? And is this not a programming question? – Nico Nekoru May 14 '20 at 17:12
  • Well the guys behind WSL, and now of course WSL 2, haven't provided with it, a seamless method of mixing the two within a single scripted environment, then it appears that its up to you to develop one yourself. Either way, your question is not appropriate for this site. – Compo May 14 '20 at 17:18
  • Technically you could just use Ubuntu and create a Bash script that runs DOS commands too. You just need to get the path of the DOS command. – Todd May 17 '20 at 00:02

1 Answers1

2

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!

Dzienny
  • 3,165
  • 1
  • 19
  • 29