Do I need to make .sh file executable on Windows?
I want to make a bash file run.sh
such that users can execute it on their systems. However, I am using Windows and am unsure if there is a similar way to make a file executable.
How I would do it on a Linux system with directory as follows:
src
├── train.py - training/optimization pipelines
└── utils.py - utility functions
requirements.txt
run.sh
README.md
Then I create run.sh
file with chmod +x run.sh
#!/bin/bash
pip install -r requirements.txt
python3 src/main.py
I got two questions:
- In Windows, do I need to type anything to make the
run.sh
file executable? - Am I calling my
python3 src/main.py
path correctly in thesh
file? Will this work for all systems?
Solution 1:
Windows does not have Bash and cannot run .sh
files natively, unless you have Bash / compatible shell installed in some way, e.g. the Windows Subsystem for Lunix (WSL). If you have that, it is Linux so chmod is the same, but it will only work from within that environment.
Otherwise you will need a Windows script, e.g. a batch file. You could put these same lines in, and save as run.bat
and it would be executable in Windows:
pip install -r requirements.txt
python3 src/main.py
(As long as pip
and python3
are in a folder in the PATH environment variable).