79670625

Date: 2025-06-18 12:22:51
Score: 2.5
Natty:
Report link
#!/bin/bash
# 2>nul 1>&2 & @echo off & CLS & goto :batch
echo "This ran in Linux."
read -esp "Press Enter to continue...:"
exit
:batch
echo This ran in Windows.
pause
exit /b

This will be the basis of a batch-bash hybrid, if you set its file properties to be executable in Linux, and name it with the .bat extension, you will be able to run it in both OSes.

To execute in Windows Command Prompt, type it's filename (with or without its extension), like this:

C:\user>filename.bat

Or like this:

C:\user>filename

To execute in Linux, you must specify the directory (or a period for the current working directory) then a forward slash, then the FULL file name, like this:

user@computer:~$ ./filename.bat

Because Linux recognises it as executable, and you specified #!/bin/bash as the topmost line, Linux will run it with bash by default.

Please downvote if it does not work on your computer.

Reasons:
  • RegEx Blacklisted phrase (2): downvote
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Unoheaken