Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Announcements and Chat > General Discussion

Reply
 
Thread Tools Search this Thread Display Modes
Old 9th March 2025, 23:56   #1  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 385
Cygwin to Run Shell Scripts on Windows

How do I use Cygwin to run MacOS/Linux shell scripts like these on Windows?

https://silvae86.github.io/2021/02/1...google-photos/
jay123210599 is offline   Reply With Quote
Old 10th March 2025, 01:07   #2  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,269
Just install Cygwin with the installer from the official web-site and then run "cygwin.bat" from Cygwin install directory to open a terminal:
https://www.cygwin.com/

But be aware: Even though Cygwin allows you to run shell scripts on Windows, and it provides most of the "standard" Unix tools (bash, make, grep, etc. pp.), not every Linux or MacOS script/command will "magically" just work 1:1 on Windows!

For example, "brew" (Homebrew) is a package manager for MacOS, so it won't work on Windows/Cygwin. If you want to install packages in Cygwin, just use Cygwin's package manager, i.e. Cygwin Setup
https://www.cygwin.com/install.html
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 10th March 2025 at 01:31.
LoRd_MuldeR is offline   Reply With Quote
Old 10th March 2025, 05:36   #3  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 385
Quote:
Originally Posted by LoRd_MuldeR View Post
Just install Cygwin with the installer from the official web-site and then run "cygwin.bat" from Cygwin install directory to open a terminal:
https://www.cygwin.com/

But be aware: Even though Cygwin allows you to run shell scripts on Windows, and it provides most of the "standard" Unix tools (bash, make, grep, etc. pp.), not every Linux or MacOS script/command will "magically" just work 1:1 on Windows!

For example, "brew" (Homebrew) is a package manager for MacOS, so it won't work on Windows/Cygwin. If you want to install packages in Cygwin, just use Cygwin's package manager, i.e. Cygwin Setup
https://www.cygwin.com/install.html
All right, I installed Cygwin, now do how I use it to run the script above so I can complete this task? https://forum.doom9.org/showthread.php?t=185986

Which file format/extension should I put the script in?
jay123210599 is offline   Reply With Quote
Old 10th March 2025, 21:14   #4  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,269
Quote:
Originally Posted by jay123210599 View Post
All right, I installed Cygwin, now do how I use it to run the script above so I can complete this task? https://forum.doom9.org/showthread.php?t=185986

Which file format/extension should I put the script in?
Usually shell scripts are stored with a ".sh" file extension.

Once you have saved the script, run "cygwin.bat" from Cygwin install directory to open a terminal, then (in the terminal) "cd" to the directory where your script file is located, and then run "./my_script.sh".

Note that a Windows path like "C:\path\to\my_script.sh" would translate to "/cygdrive/c/path/to/my_script.sh" in Cygwin.

__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 10th March 2025 at 21:20.
LoRd_MuldeR is offline   Reply With Quote
Old 10th March 2025, 22:43   #5  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 385
Quote:
Originally Posted by LoRd_MuldeR View Post
Usually shell scripts are stored with a ".sh" file extension.

Once you have saved the script, run "cygwin.bat" from Cygwin install directory to open a terminal, then (in the terminal) "cd" to the directory where your script file is located, and then run "./my_script.sh".

Note that a Windows path like "C:\path\to\my_script.sh" would translate to "/cygdrive/c/path/to/my_script.sh" in Cygwin.

Here is the file path of my script: "C:\Users\User\Downloads\my_script.sh"

What does that translate to? Is there a tool for this sort of thing? Also, do I add "./" at the beginning of it?
jay123210599 is offline   Reply With Quote
Old 11th March 2025, 00:48   #6  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,269
Quote:
Originally Posted by jay123210599 View Post
Here is the file path of my script: "C:\Users\User\Downloads\my_script.sh"
What does that translate to?
/cygdrive/c/Users/User/Downloads/my_script.sh

Quote:
Originally Posted by jay123210599 View Post
Is there a tool for this sort of thing?
Yes, and it's called "cygpath"

But you don't normally need that. It's not that complicated. All your Windows "drives" are mounted at "/cygdrive/x/" by default, with "x" being the corresponding Windows "drive letter".

So, your "C:" drive will be mounted at "/cygdrive/c/", your "D:" drive will be mounted at "/cygdrive/d/", and so on...

Quote:
Originally Posted by jay123210599 View Post
Also, do I add "./" at the beginning of it?
If you want to run an executable or script from the current directory (rather than specifying an absolute path), then yes, you have to put a "./" in front of it!

So, with your example, you can either run "cd /cygdrive/c/Users/User/Downloads" followed by "./my_script.sh", or you can just run "/cygdrive/c/Users/User/Downloads/my_script.sh".
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 11th March 2025 at 01:00.
LoRd_MuldeR is offline   Reply With Quote
Old 11th March 2025, 00:55   #7  |  Link
jay123210599
Registered User
 
Join Date: Apr 2024
Posts: 385
Quote:
Originally Posted by LoRd_MuldeR View Post
If you want to run a script from the current directory (rather than specifying an absolute path), then yes, you have to put a "./" in front of it.
Like this?

.//cygdrive/c/Users/User/Downloads/my_script.sh
jay123210599 is offline   Reply With Quote
Old 11th March 2025, 01:02   #8  |  Link
LoRd_MuldeR
Software Developer
 
LoRd_MuldeR's Avatar
 
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,269
Quote:
Originally Posted by jay123210599 View Post
Like this?

.//cygdrive/c/Users/User/Downloads/my_script.sh
Uhm, no

As said above, either you use the "cd" command to change the current directory to the directory where your script is located (e.g. "cd /cygdrive/c/Users/User/Downloads"), and then you run "./my_script.sh".

...or you enter the absolute path of the script that you want to run, which would be "/cygdrive/c/Users/User/Downloads/my_script.sh" in your case.


(As an aside: You can always run the "pwd" command to check in which directory you currently are!)
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊

Last edited by LoRd_MuldeR; 11th March 2025 at 01:12.
LoRd_MuldeR is offline   Reply With Quote
Reply

Tags
cygwin, scripts

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:03.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.