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

  • So far I tried using the empty bash and ubuntu commands alone since they switch the normal command-prompt to the Ubuntu/Bash shell, but even if you put commands after the ubuntu/bash they wouldn't show or do anything.

  • After I tried that, I tried using the ubuntu -run command, but like I said earlier, it’s really fickle and inconsistent on what things work and what things don't. It is less inconsistent when you pipe things into it, but it 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).

  • I also looked to this and I guess it failed 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nico Nekoru
  • 2,840
  • 2
  • 17
  • 38
  • 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!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dzienny
  • 3,295
  • 1
  • 20
  • 30