LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cross platform BASH scripts? (https://www.linuxquestions.org/questions/programming-9/cross-platform-bash-scripts-759208/)

celticdaddio 10-02-2009 09:31 AM

Cross platform BASH scripts?
 
I currently have apps that are compiled for execution on Windows and Linux and distributed.

I have a bash script that collects and tars the files needed for a linux distribution. I have similar batch files on winows.

Rather than maintain and enhance, as needed, a bash script and a batch file for every product, I would like to have a single script for each app, maybe even a single script for all apps, on both linux and windows.

I had originally thought about using python, or perl, to do this, but I already have pretty decent bash files and batch files done.

I know I can run bash scripts under Cygwin on a windows machine, but will that allow me to access all the files on the Windows machine, outside of the cygwin home?

Any suggestions on how YOU would handle this?

CD

TB0ne 10-02-2009 10:32 AM

Quote:

Originally Posted by celticdaddio (Post 3705042)
I currently have apps that are compiled for execution on Windows and Linux and distributed.

I have a bash script that collects and tars the files needed for a linux distribution. I have similar batch files on winows.

Rather than maintain and enhance, as needed, a bash script and a batch file for every product, I would like to have a single script for each app, maybe even a single script for all apps, on both linux and windows.

I had originally thought about using python, or perl, to do this, but I already have pretty decent bash files and batch files done.

I know I can run bash scripts under Cygwin on a windows machine, but will that allow me to access all the files on the Windows machine, outside of the cygwin home?

Any suggestions on how YOU would handle this?

CD

Well, I'd probably drop support for Windows, which would greatly simplify things. :)

As far as I can remember, Cygwin will only be able to see what's in the Cygwin home, but I could be mistaken. Don't have alot of experience with it, but I do seem to remember that. Perl is a great solution, but you may have problems with Windows, though, since not all Windows boxes have a decent (or any) Perl installation.

If you had a Samba mount from your Linux box to your Windows box (smbclient), you could use your Linux script to create a Windows 'set', or use Windows to mount the Linux box, and do it the other way around.

Without knowing more about your environment, and what you're trying to do, it's hard to say more.

catkin 10-02-2009 10:37 AM

Install MKS on the Windows systems? Mortice Kern Systems? *n*x utilities running under native Windows?

pwc101 10-02-2009 10:41 AM

Quote:

Originally Posted by celticdaddio (Post 3705042)
I know I can run bash scripts under Cygwin on a windows machine, but will that allow me to access all the files on the Windows machine, outside of the cygwin home?

Yes. All drives available in Windows (C:\, D:\, E:\ etc.) are "mounted" under /cygdrive with their respective drive letter as the folder. Cygwin has a clever parser for Windows paths, thus, to access C:\Program Files using Cygwin, you can either do:
Code:

cd "C:\Program Files"
Or, you can do:
Code:

cd /cygdrive/c/Program\ Files

celticdaddio 10-02-2009 02:15 PM

Thanks for all the answers. Is sounds like Cygwin may be my best choice. How about MinGW/MSYS? I had forgotten about MinGW/MSys until after I posted my question(s).

CD

smeezekitty 10-02-2009 02:17 PM

MinGW / MSYS works fine also

gnashley 10-03-2009 03:25 AM

There are also strand-alone nix-like utilities for use under win32, but no full bash shell. I have seen a version of zsh for windows. Would save having to have msys or cigwin installed, but you'd probably have to change some of your script syntax to use zsh instead of bash.

vonbiber 10-03-2009 05:22 AM

I had used zsh from the unixutils in sourceforge in all
versions of windows up to XP with no problems.
However in vista it didn't work so well (crashes occasionaly).

msys on the other hand (with bash as its default shell) worked
perfectly in vista

As far as I'm concerned msys is much better than cygwin.

If you use standard sh syntax you can use exactly the same script
with bash or zsh (zsh has features found in korn and bash shell
but it uses a different syntax on some of these: arrays, setting
the prompts PS1, etc.)

catkin 10-03-2009 05:46 AM

Quote:

Originally Posted by catkin (Post 3705120)
Install MKS on the Windows systems? Mortice Kern Systems? *n*x utilities running under native Windows?

Sorry for part-information; I was in a hurry and wanted to at least leave some pointers that might be useful. MKS may help; it is commercial and has shifted its focus from "UNIX utilites on Windows" to "Developlment life cycle toolkits". Nonetheless, from the MKS site, "MKS Toolkit for Developers ships with many commands and utilities — awk, sed, Perl, CShell, KornShell, Graphical KornShell, and more". According to this press release, bash is included in version 8.6.


All times are GMT -5. The time now is 01:26 PM.