Installing eclim on osx 10.8.5 fails - no acceptable grep found - gcc

Im trying to install eclim on OSX 10.8.5 and the installer fails because it does not like the grep I have installed.
[ANT][exec]configure: error: no acceptable grep could be found
[ANT][exec] checking for grep that handles long lines and -e...
My grep has -e
SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
What is going on here?

I ended up fixing this by using macports to install gcc grep. Apparently OSX now uses bsd grep by default and there are differences between the two that gcc was choking on. The part of this that a little ridiculous is that I installed gcc through XCode.

Related

How to install GNU grep on Mac OS?

I need to install GNU grep on my Mac but I'm finding some difficulties.
I tried doing this:
brew install grep --with-default-names
But this is no longer an option since Homebrew removed --with-default-names.
Can anyone provide a solution for this?
Yes, --with-default-names was removed.
But some formulas, like grep, provided a workaround for this:
$ brew info grep
...
==> Caveats
All commands have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
...
First, to install, just do install without --with-default-names.
$ brew install grep
...
==> Summary
🍺 /usr/local/Cellar/grep/3.3: 21 files, 880.7KB
You should also see that same "Caveats" info I mentioned at the start. Now, by default, the Homebrew grep would be prefixed by a "g", so it's accessible as ggrep.
$ ggrep -V
ggrep (GNU grep) 3.3
Packaged by Homebrew
Copyright (C) 2018 Free Software Foundation, Inc.
...
This prevents it from shadowing the built-in grep that comes with Mac.
$ grep -V
grep (BSD grep) 2.5.1-FreeBSD
If you really need to use grep and not ggrep, just follow the instructions and put /usr/local/opt/grep/libexec/gnubin at the start of your PATH. You have to do this in your .bashrc or .bash_profile (whichever one you use).
$ echo 'export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ grep -V
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
grep (GNU grep) 3.3
Packaged by Homebrew
...

Find the latest version of gcc and switch to it

I installed multiple versions of gcc on a Ubuntu 16.04 and I'm wondering how to set up the system to use the latest version of gcc without uninstalling the older ones.
I'd prefer if it was a simple script and not a dependency because I'm installing it in a Docker container and I don't want to bloat it.
# list everything in /usr/bin
# leave the ones that start with gcc
# remove everything but the version numbers
# remove anything but the numbers
# sort them
# get the last one
version=$(ls /usr/bin/ | grep '^gcc' | cut -d'-' -f2 | grep -o '[0-9]\+\(\.[0-9]\+\)\?' | sort | tail -n 1)
# remove the symbolic link to the current version of gcc
rm /usr/bin/gcc
# remove the symbolic link to the current version of g++
rm /usr/bin/g++
# create symbolic links to the latest versions
ln -s /usr/bin/g++-${version} /usr/bin/g++
ln -s /usr/bin/gcc-${version} /usr/bin/gcc

mv command not working on mac

Here is the part of the makefile that is giving me issues:
-#mv -f -t ./ $(LIBPATH)/userfiles/*
When I run the makefile on Ubuntu it works fine however when running on my Mac I get the following error:
mv: illegal option -- t usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
The -t flag is not defined in the man pages of my mac so I'm wondering how I can get around this.
Just put the destination at the end like how mv is normally used:
-#mv -f $(LIBPATH)/userfiles/* .
You are allowed to have multiple sources (such as the expanded wildcard here). The last argument is the destination. The -t flag is just a way to change this ordering if you have to for some reason, and (as you discovered) it is not always available.
Install coreutils by typing the following command in the terminal:
brew install coreutils
Commands also provided by macOS and the commands dir, dircolors, vdir have been installed with the prefix "g".
If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH with:
PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH"
Reference:
coreutils - Homebrew Formulae

Mac OS X /usr/bin/time verbose flag

I have been trying to run the usr/bin/time command in my terminal (Bash) with the verbose flag --verbose or -v but have repeatedly been getting this error:
/usr/bin/time: illegal option -- v
usage: time [-lp] command.
The command I have been running looks like basically like this:
/usr/bin/time -v python practice.py
Any ideas how to get this to work properly on a Mac? (I have OS X Yosemite)?
If you have homebrew, you can get GNU time by installing the gnu-time package:
brew install gnu-time
After that, it’s available as the gtime command:
$ gtime
Usage: gtime [-apvV] [-f format] [-o file] [--append] [--verbose]
[--portability] [--format=format] [--output=file] [--version]
[--help] command [arg...]
The case is similar for a lot of other homebrew-packaged GNU utilities for OSX; e.g., you can get the GNU df command with gdf, du with gdu, readlink with greadlink, etc.
The homebrew package that has most of those is coreutils, which installs about a hundred different GNU-flavored commands. Other useful packages: findutils, gnu-sed, gnu-tar.
If you don’t have homebrew installed yet, you can get it with just a single command:
Command to download and install homebrew
ruby -e "$(curl -fsSL\
https://raw.githubusercontent.com/Homebrew/install/master/install)"
I think looking at the man page the verbose flag is GNU only. Unfortunately, OSX implementation simply differs.

How to break a xml line into several lines using bash script?

I'm a beginner in bash script and cannot solve the following problem: I have a file where each line is a xml file. I would like to divide each line into several lines.
For instance, I would like to put the following line:
<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>
into the format:
<LumiBlockCollection>
<Run>201556</Run>
<LBRange Start="1020" End="1030"/>
</LumiBlockCollection>
Does anyone know how to solve this problem?
In general, for a robust solution that works with varying input data, you should use an XML parser for this task:
A solution based on xmllint - xmllint is a standard utility on OS X and some Linux distros (e.g., Fedora):
echo '<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>' \
| XMLLINT_INDENT= xmllint --format - | tail -n +2
If your Linux distro does not come with xmllint, chances are that it can be installed with your platform's package manager; e.g., on Debian-based distros such as Ubuntu:
sudo apt-get install libxml2-utils
Another solution, based on third-party utility xmlstarlet:
echo '<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>' \
| xmlstarlet fo --omit-decl --noindent
Obtaining xmlstarlet:
OSX: Install via Homebrew with brew install xmlstarlet
Linux: chances are that it can be installed with your platform's package manager; e.g., on Debian-based distros such as Ubuntu: sudo apt-get install xmlstarlet
Here's a simple solution using sed. Note that if you have CDATA sections, this will place them on their own line:
$ xml='<LumiBlockCollection><Run>201556</Run><LBRange Start="1020" End="1030"/></LumiBlockCollection>'
$ echo $xml | sed 's/></>\n</g'
<LumiBlockCollection>
<Run>201556</Run>
<LBRange Start="1020" End="1030"/>
</LumiBlockCollection>
$

Resources