Parallels For Mac Unable To Detect Operating System
Using Parallels Desktop 9 for Mac you can run several other kinds of operating systems (p. 134) on your Mac, such as several flavors of Linux and Unix, Mac OS X Server, Windows 8, older versions of Windows, and more. Parallels Toolbox for Mac and Windows. 30+ tools in a lightweight, powerful, all-in-one application for Mac ® and PC. Easy to use and economical—a whole suite of tools for a fraction of the cost of individual apps, packaged in one simple interface.
I have a shell script that is used both on Windows/Cygwin and Mac and Linux. It needs slightly different variables for each versions.
How can a shell/bash script detect whether it is running in Cygwin, on a Mac or in Linux?
bastibebastibe11 Answers
Usually, uname with its various options will tell you what environment you're running in:
And, according to the very helpful schot (in the comments), uname -s gives Darwin for OSX and Linux for Linux, while my Cygwin gives CYGWIN_NT-5.1. But you may have to experiment with all sorts of different versions.
So the bash code to do such a check would be along the lines of:
Note that I'm assuming here that you're actually running within CygWin (the bash shell of it) so paths should already be correctly set up. As one commenter notes, you can run the bash program, passing the script, from cmd itself and this may result in the paths not being set up as needed.
If you are doing that, it's your responsibility to ensure the correct executables (i.e., the CygWin ones) are being called, possibly by modifying the path beforehand or fully specifying the executable locations (e.g., /c/cygwin/bin/uname).
Pay attention
- In your bash script, use
#!/usr/bin/env bashinstead of#!/bin/shto prevent the problem caused by/bin/shlinked to different default shell in different platforms, or there will be error like unexpected operator, that's what happened on my computer (Ubuntu 64 bits 12.04). - Mac OS X 10.6.8 (Snow Leopard) do not have
exprprogram unless you install it, so I just useuname.
Design
Mac Unable To Detect Android Phone
- Use
unameto get the system information (-sparameter). - Use
exprandsubstrto deal with the string. - Use
ifeliffito do the matching job. - You can add more system support if you want, just follow the
uname -sspecification.
Implementation
Testing
- Linux (Ubuntu 12.04 LTS, Kernel 3.2.0) tested OK.
- OS X (10.6.8 Snow Leopard) tested OK.
- Windows (Windows 7 64 bit) tested OK.
What I learned
- Check for both opening and closing quotes.
- Check for missing parentheses and braces {}
References
- [1] uname - wikipedia
- [2] shell script syntax error: unexpected end of file
- [3] Detect the OS from a Bash script
- [4] BASH Programming Introduction HOW-TO
Use uname -s (--kernel-name) because uname -o (--operating-system) is not supported on some Operating Systems as Mac OS, Solaris. You may also use just uname without argument as the default argument is -s (--kernel-name).
The below snippet does not require bash (i.e. does not require #!/bin/bash)
The below Makefile is inspired from Git project (config.mak.uname).
See also this complete answer about uname -s and Makefile.
Parallels For Mac Unable To Detect Operating System Windows 10
The correspondence table in the bottom of this answer is from Wikipedia article about uname. Please contribute to keep it up-to-date (edit the answer or post a comment). You may also update the Wikipedia article and post a comment to notice me about your contribution ;-)
Operating System uname -s Mac OS X Darwin Cygwin 32-bit (Win-XP) CYGWIN_NT-5.1 Cygwin 32-bit (Win-7 32-bit)CYGWIN_NT-6.1 Cygwin 32-bit (Win-7 64-bit)CYGWIN_NT-6.1-WOW64 Cygwin 64-bit (Win-7 64-bit)CYGWIN_NT-6.1 MinGW (Windows 7 32-bit) MINGW32_NT-6.1 MinGW (Windows 10 64-bit) MINGW64_NT-10.0 Interix (Services for UNIX) Interix MSYS MSYS_NT-6.1 Windows Subsystem for LinuxLinux Android Linux coreutils Linux CentOS Linux Fedora Linux Gentoo Linux Red Hat Linux Linux Linux Mint Linux openSUSE Linux Ubuntu Linux Unity Linux Linux Manjaro Linux Linux OpenWRT r40420 Linux Debian (Linux) Linux Debian (GNU Hurd) GNU Debian (kFreeBSD) GNU/kFreeBSD FreeBSD FreeBSD NetBSD NetBSD DragonFlyBSD DragonFly Haiku Haiku NonStop NONSTOP_KERNEL QNX QNX ReliantUNIX ReliantUNIX-Y SINIX SINIX-Y Tru64 OSF1 Ultrix ULTRIX IRIX 32 bits IRIX IRIX 64 bits IRIX64 MINIX Minix Solaris SunOS UWIN (64-bit Windows 7) UWIN-W7 SYS$UNIX:SH on OpenVMS IS/WB z/OS USS OS/390 Cray sn5176 (SCO) OpenServer SCO_SV (SCO) System V SCO_SV (SCO) UnixWare UnixWare IBM AIX AIX IBM i with QSH OS400 HP-UX HP-UX
Bash sets the shell variable OSTYPE. From man bash:
Automatically set to a string that describes the operating system on which bash is executing.
This has a tiny advantage over uname in that it doesn't require launching a new process, so will be quicker to execute.
However, I'm unable to find an authoritative list of expected values. For me on Ubuntu 14.04 it is set to 'linux-gnu'. I've scraped the web for some other values. Hence:
The asterisks are important in some instances - for example OSX appends an OS version number after the 'darwin'. The 'win' value is actually 'win32', I'm told - maybe there is a 'win64'?
• It has a snappy propelling method for applications. • Run Windows on Mac without rebooting.
• Handles how to utilize numerous OS with various situations. • Presently with 500 GB of free online stockpiling for one year, controlled by Acronis.
Perhaps we could work together to populate a table of verified values here:
- Linux Ubuntu (incl. WSL):
linux-gnu - Cygwin 64-bit:
cygwin - Msys/MINGW (Git Bash for Windows):
msys
(Please append your value if it differs from existing entries)
To build upon Albert's answer, I like to use $COMSPEC for detecting Windows:
This avoids parsing variants of Windows names for $OS, and parsing variants of uname like MINGW, Cygwin, etc.
Background: %COMSPEC% is a Windows environmental variable specifying the full path to the command processor (aka the Windows shell). The value of this variable is typically %SystemRoot%system32cmd.exe, which typically evaluates to C:Windowssystem32cmd.exe .
If the 6 first chars of uname -s command is 'CYGWIN', a cygwin system is assumed
doekmanAll the info you'll ever need. Google is your friend.
Use uname -s to query the system name.
- Mac:
Darwin - Cygwin:
CYGWIN_.. - Linux: various,
LINUXfor most
I guess the uname answer is unbeatable, mainly in terms of cleanliness.
Although it takes a ridiculous time to execute, I found that testing for specific files presence also gives me good and quicker results, since I'm not invoking an executable:
So,
[ -f /usr/bin/cygwin1.dll ] && echo Yep, Cygwin running
just uses a quick Bash file presence check. As I'm on Windows right now, I can't tell you any specific files for Linuxes and Mac OS X from my head, but I'm pretty sure they do exist. :-)
Windows Subsystem for Linux did not exist when this question was asked. It gave these results in my test:
This means that you need uname -r to distinguish it from native Linux.
Use only this from command line works very fine,thanks to Justin:
protected by Hovercraft Full Of EelsJun 14 '18 at 19:54
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged bashshellcross-platformcygwin or ask your own question.
Hmm. you were able to reinstall the OS so you were able to boot a CD/DVD from the image - was there a Win7 repair option?
With the reinstalled OS, the files stored on it should be available, unless it was reformatted.
From Parallels Help under 'Browsing Virtual Hard Disks in Finder':
If you want to manage the virtual machine content without starting the virtual machine, you can mount the virtual hard disks manually using Parallels Mounter:
Browse the virtual machine files in Finder. For Parallels virtual machines, right-click the virtual machine name in the Parallels Virtual Machines list and select Show in Finder from the context menu.
The default paths for storing Parallels virtual machines are /Users/<UserName>/Documents/Parallels/ and /Users/Shared.
To mount the hard disk of a particular virtual machine, right-click this virtual machine's file and choose Open With > Parallels Mounter or Open With > Other > Library > Parallels > Parallels Mounter from the shortcut menu. You can mount the following virtual machines and hard disks:
Parallels bundle (.pvm) or configuration file (.pvs) or virtual hard disk file (.hdd).
VMware configuration file (.vmx, .vmwarevm) or virtual hard disk file (.vmdk).
Virtual PC configuration file (.vmc, .vpc7) or virtual hard disk file (.vhd).
VirtualBox configuration file (.xml) or virtual hard disk file (.vdi).
If you choose the PVM file of a Parallels virtual machine or the configuration file of a third-party virtual machine that has several virtual hard disks, all its volumes will appear as mounted in Finder.
If you want to mount a single virtual hard disk, double-click the virtual hard disk file to mount it with Parallels Mounter. The icon for the selected hard disk appears in the sidebar of the Finder window, together with other Mac OS X icons.
To browse the contents of a volume, click its icon in the sidebar of the Finder window.
You can manage the virtual machine files just as you manage your Mac OS X files in Finder windows.
Note: If you are browsing the contents of a suspended virtual machine in Finder, you cannot delete, move, or otherwise modify its files.
To unmount the volume, use the Eject button next to the disk icon.
Note: If a hard disk that has several volumes was mounted and you want to open it or the virtual machine using it in Parallels Desktop, you should disconnect its volumes one by one by clicking the Eject button.