Linked Questions
33 questions linked to/from How to detect the OS from a Bash script?
5
votes
3
answers
3k
views
how can I recognize which OS I am on in a bash script [duplicate]
I need to make script that behaves differently per system. Today it is possible to run bash even on microsoft windows, mac, linux, hp-ux, solaris etc...
How can I determine which of these operating ...
0
votes
1
answer
609
views
Is there a command working on BOTH linux and mac OS for determining the OS version? [duplicate]
I know there is, for example, hostnamectl command on linux and system_profiler SPSoftwareDataType command on macOS to know the operating system version, but I'm looking for a command that works for ...
1686
votes
15
answers
1.0m
views
echo that outputs to stderr
Is there a standard Bash command that acts like echo but outputs to stderr rather than stdout?
I know I can do echo foo 1>&2 but it's kinda ugly and, I suspect, error-prone (e.g. more likely to ...
488
votes
11
answers
250k
views
How to check if running in Cygwin, Mac or Linux?
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 ...
133
votes
14
answers
74k
views
Single script to run in both Windows batch and Linux Bash?
Is it possible to write a single script file which executes in both Windows (treated as .bat) and Linux (via Bash)?
I know the basic syntax of both, but didn't figure out. It could probably exploit ...
51
votes
3
answers
39k
views
base64 doesnt have -w option in Mac
I am trying to use base64 but the script doesn't run successfully in Ubuntu machine
MYCOMMAND=$(base64 commands.sh)
So in Ubuntu , I have to use
MYCOMMAND=$(base64 -w0 commands.sh)
unfortunately ...
21
votes
8
answers
68k
views
check if argument is a valid date in bash shell
I am writing a bash shell script in Linux, this program will accept a date (mm-dd-yyyy) as a parameter. I am wondering if there is a simply way to check if the date is valid? is there an operator and ...
28
votes
5
answers
29k
views
Executing a script in MSYS2/MinGW
On Windows, if I start c:\msys64\mingw64.exe, it opens a shell, where I can build my project, let's say by calling a release bash script (to simplify). Everything works fine.
Now, I would like to ...
18
votes
5
answers
33k
views
How to determine the current operating system in a Jenkins pipeline
What would be the way to determine the current OS a Jenkins pipeline is running?
Context: I'm building a shared Jenkins pipeline script that should run on all platforms (windows, OSX, linux) and ...
11
votes
3
answers
26k
views
String comparison in bash is not working
Hi I'm new to bash scripting. Just wrote this simple program but it is throwing error.
#!/bin/bash
os=`uname -o`
echo $os
if ["$os"=="GNU/Linux"] ; then
echo "Linux"
else
echo "Windows"
fi
...
22
votes
3
answers
19k
views
Adding MSYS to windows terminal
I added bash on windows to windows terminal by editing the settings.json file, when I try to compile a simple hello world written in c++ it throws an error that gcc or g++ is not detected
How to ...
33
votes
3
answers
30k
views
Where is the list of the POSIX C API functions? [closed]
I'm trying to find out where I can find documentation on POSIX functions, but coming up short. Any recommendations?
7
votes
3
answers
12k
views
Shell Script to find the Operating System of the machine
How to find the operating system using bash script? I found this answer: Detect the OS from a Bash script. It is not clear it would work on Mac OS X.
I would like to find it on Mac OS X vs different ...
9
votes
3
answers
5k
views
How to check whether shell scripts / Vim running in VS Code integrated terminal?
Issue
Question is as stated in the title.
In gist, I am trying to get my bash scripts and Vim to behave differently when running in VS Code's integrated terminal.
Things I've found
I have managed ...
15
votes
2
answers
9k
views
How to detect OS and load ZSH settings conditionally?
I use several different OS's at home and work and I want to be able to load platorm-specific ZSH settings conditionally, depending on which OS I'm using at the given moment.
I tried this but it doesn'...