For the last 5 years, I have used linux as my everyday OS for performing scientific computing. My work recently gave me a Mac that I will be the primary user for the next few months. I keep running into conflicts between the Free-BSD bash environment on the Mac and the GNU environment I am used to, both with bash scripts I have setup and as I try to run bash commands (coreutils
, findutils
, etc). I do not want to switch completely to the Free-BSD utilies as all my other computers as well as our HPC's use linux with the GNU utilities. I want to avoid having to maintain two sets of bash scripts and also having to remember the nuances of the differing flags and functionalities between the two systems. I also do not want to break any of Mac's gui utilites etc that other users will use (either in the next few months or when it is given to someone else). Additionally, responses to this related question warn against completely replacing the Mac Free-BSD utilities with GNU ones.
Is it possible to install/setup a separate bash environment to use only the GNU utilities while leaving the system Free-BSD ones in place? My expect the most promising option is setting up my $PATH
variable to point to a directory containing the GNU executables (with their standard names) while ignoring the Free-BSD ones. How could I apply this to my cross-platform bash scripts? Are there alternative options worth considering?
bash
, but the question text seems to be aboutcoreutils
. OS X has hadbash
for many years. – Barmar Jul 17 '15 at 15:54$PATH
. – mikeserv Jul 17 '15 at 16:16prefix/libexec/gnubin
should be installed. Which is a directory with symbolic links to the binaries prefixed with a g. That directory would be the first one in your PATH. – fd0 Jul 17 '15 at 16:22chroot
perhaps? – glenn jackman Jul 17 '15 at 16:26chroot
is awfully heavy-handed for this. Your entire Linux working environment would have to be copied or linked into thatchroot
for this to work. You couldn't confidently use GNUgrep
on~/Documents
instead of BSDgrep
, for example, without making it available there, too. And then what happens if you want to go grepping around in/Library/Application Support
? Potentially the whole system needs to bechroot
ed. – Warren Young Jul 17 '15 at 16:41