Active4 months ago
The New Virtual Machine Wizard cannot automatically detect the installation media (a CD/DVD or an.iso file). When adding the installation media manually the following warning is displayed: 'Unable to detect operating system. This is a how to guide for installing Windows 98 SE as a virtual machine in Parallels Desktop 3.0 for Mac. It was created using Mac OS 10.4.10, Parallels Desktop 3.0 Build 5160 and a bootable Windows 98SE CDROM.
'Unable to detect operating system' Discussion in 'Installation and Configuration' started by YasminaA, Sep 22, 2015. You may see a warning saying “Unable to detect operating system”. Click “Continue” and select “macOS” as the operating system.
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?
bastibebastibe7,0162222 gold badges7777 silver badges115115 bronze badges
11 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.,
paxdiablopaxdiablo/c/cygwin/bin/uname
).666k185185 gold badges13231323 silver badges17231723 bronze badges
Pay attention
![Operating Operating](https://www.copytrans.net/support/wp-content/uploads/sites/2/2013/04/parallels-mac-run-copytrans.png)
- In your bash script, use
#!/usr/bin/env bash
instead of#!/bin/sh
to prevent the problem caused by/bin/sh
linked 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
expr
program unless you install it, so I just useuname
.
Design
- Use
uname
to get the system information (-s
parameter). - Use
expr
andsubstr
to deal with the string. - Use
if
elif
fi
to do the matching job. - You can add more system support if you want, just follow the
uname -s
specification.
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
Community♦
AlbertAlbert7,78144 gold badges1818 silver badges2727 bronze badges
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
.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 Linux
Linux
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
29.4k2121 gold badges120120 silver badges160160 bronze badges
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'?
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:
Steve JansenSteve Jansen%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
.7,86022 gold badges2222 silver badges3030 bronze badges
If the 6 first chars of uname -s command is 'CYGWIN', a cygwin system is assumed
doekman9,5541616 gold badges5959 silver badges7676 bronze badges
Jan HelgeJan Helge
Mac Unable To Detect Android Phone
All the info you'll ever need. Google is your friend.
![Windows Windows](/uploads/1/2/6/0/126070107/595996925.png)
Use
uname -s
to query the system name.- Mac:
Darwin
- Cygwin:
CYGWIN_...
- Linux: various,
LINUX
for most
4,18844 gold badges2323 silver badges3535 bronze badges
rubenvbrubenvb55.6k2424 gold badges146146 silver badges265265 bronze badges
wenerwener3,90244 gold badges3434 silver badges5353 bronze badges
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. :-)
Charles Roberto CanatoCharles Roberto Canato
Parallels For Mac Unable To Detect Operating System Windows 10
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.
A FogA Fog
Use only this from command line works very fine,thanks to Justin:
lizardhrlizardhr
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?
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.
Up to Date
Optimized for the latest Windows 10 updates and ready for macOS Catalina (10.15).
Ultimate Flexibility
Works with OS X, Windows 10, 8.1, and 7, Google Chrome™,Linux and Unix, and macOS Server. No more having to choose between PC or Mac.
Touch Bar
Add Windows applications to Touch Bar™ for instant access and customization.
Connect Devices
USB, USB-C, Thunderbolt and FireWire devices connect with Windows. Pair your Bluetooth® devices—including Xbox One controller, stylus pen and printer—to work with both Windows and macOS.
Retina® Display Support
Smart resizing and independent screen resolutions for separate displays.
One-Click Tuning
Select productivity, games, design, software testing, or development, and Parallels Desktop will optimize your VM settings and performance for you.
Instant Access
Launch and access Windows applications right from the Mac Dock.
Save Disk Space
Get the most out of your Mac with automatic Disk Space optimization.
Office 365 Integration
Allows Word, Excel, or PowerPoint documents in Safari to open in their native Windows Office application.
Works with Boot Camp
Reuse your existing Boot Camp installation. Converting a virtual machine from Boot Camp is easy—just follow our installation assistant at startup.
Volume License Key
Unified volume license key, centralized license management, and advanced security features are available in Parallels Desktop for Mac Business Edition.
Travel Mode
Extend battery life while away from a power source.
Bonus! Parallels® Toolbox
Over 30 one-touch tools—clean your drive, take screenshots, download a video, and more, all with just a single click.
Bonus! Remote Access
Remote access to your Mac from any iOS device, Android device, or browser with Parallels Access®.
24/7 Support
Premium 24/7 phone, email, and social support after activation.
- Share Mac applications with Windows
- Automatic resolution change
- Single cloud storage space between Mac and Windows
- Drag and drop files between Mac and Windows
- Copy and paste files or text between Mac and Windows
- Launch Windows applications right from the Dock
- Move your PC to Mac in a few easy steps
- Assign any USB devices to your Mac or Windows
- Retina display support for Windows
- Volume control synchronization
- Open any site in Microsoft Explorer right from Safari® browser
- Apply macOS Parental Control to Windows applications
- Windows alerts in Mac Notification Center
- Mac dictation inside Windows applications
- See the number of unread emails in the Dock
- “Reveal in Windows Explorer” in macOS files menu
- Virtual machine encryption
- Linked clones for VMs*
- Vagrant provider*
- 32 vCPUs and 128 GB vRAM*
- Nested virtualization for Linux*
- Drag and drop files in macOS guests
- Real-time virtual disk optimization
- Create VM from VHD and VMDK disks*
- Drag and drop to create VM
- Disk Space Wizard optimizes your disk space
- Shared folders and printers for Linux VMs
- Windows applications in Launchpad
- Power Nap in Windows
- Use Force Touch to look up definitions
- New virtual machine wizard
- Mission Control support
- Presentation Wizard prevents most projector issues
- Drop files onto Outlook to create a new message
- Multi-language keyboard sync
- Picture-in-Picture view
- Share Bluetooth between Mac and Windows
- macOS guest support
- Spaces functionality for Windows applications
- Mission Control exposes your Windows applications
- DirectX support
- Thunderbolt support
- Licensing portal*
- Firewire support
- USB-C and USB 3.0 support
- Work without risk with Snapshots
- Safeguard your VM with encryption
- 2 GB video memory support
- Finder tabs work with Windows applications
- AVX512 instruction set support
- Mojave support
- Disk usage optimizations
- Report disk space left on Mac
- Express installation of Windows 10
- Native Mojave screenshots
- Auto allocation of video memory
- “Free Up Disk Space” wizard
- Free OS downloads
- Coherence for external displays
- Continuity camera support
- Touch Bar support
- Shared smart card reader
- Multi-monitor support
- 4K shared camera support
- CPU usage indicator
- Mojave Quick Look support
- Pressure sensitivity support
- Resource usage monitor
- OpenGL support
- Offer to import Boot Camp
- Auto-detect games keyboard
- And many more…
*Available with Parallels Desktop Pro Edition and Business Edition subscriptions