I have this bash command that uses rar
for folder in */; do rar a -m0 -r "${folder%/}.rar" "$folder"; done
I understand from https://stackoverflow.com/questions/25299584/create-a-rar-archive-for-each-subdirectory-in-a-directory-centos-ubuntu that it creates a rar archive of each subdirectory of a directory. But that link covers ubuntu. I'm wondering how i'd run that in Windows.
I understand that Gnuwin32 is full of old versions of programs and doesn't even have rar anyway.
Cygwin is newer but doesn't include rar.exe in its list of packages.
If I try even doing $rar in cygwin, then it says
rar: command not found
What can I do?
Best Answer
There's two ways you could do this.. one way is to run rar.exe from cmd.exe without cygwin. But then you'd need to adjust your command to run with batch rather than bash.
The other way is to run rar.exe from cygwin. Then you can use your bash command directly. We'll try that route
You can run external executables from within cygwin.
you can get the rar command for windows quite easily and it ends up in
C:\Program Files\WinRAR\Rar.exe
Install winrar from rarlab.com/download.htm which mentions rarlab.com/rar/winrar-x64-602.exe
Then you have to know how to add a directory to a shell's path variable, so you can run rar.exe from any directory (and in your case since using cygwin, that'd be the bash way of adding a directory to the path variable)
And if you look
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\WinRAR
it'll have a manual for how to use the command line rar.exeSo you see now you have rar running.
And now your command will run just as good as it does here
https://stackoverflow.com/questions/25299584/create-a-rar-archive-for-each-subdirectory-in-a-directory-centos-ubuntu
And as the user showed, having removed the echo. And set up cygwin bash's path, and installed winrar including the command line rar.exe and then running the command.