I occasionally do work on an older Solaris machine whose version of `grep` is incomplete. This causes problems in my rc files because the default `grep` on the machine doesn't support the options I need.
This is a machine at work, and I'm not an admin; so I can't just install newer/better versions of commands as I see fit. However, I notice that the machine does have a suitable [XPG][1] version of `grep` in `/usr/xpg4/bin/grep`.
Obviously, I can solve the problem in my rc files with:
alias grep='/usr/xpg4/bin/grep'
But what about machines where this isn't necessary? My goal is to have a single rc file for each shell that I can drop into any Unix-like system and have it just work.
This got me thinking...
1. Is there ever a case where I wouldn't want to use the [XPG][1] version of a command?
* If so, when?
2. Couldn't I just blindly add `/usr/xpg4/bin/` to the beginning of `$PATH` in my rc files on all machines and forgo aliasing individual commands to their XPG* versions?
* Or will this cause problems for some commands?
3. Is it the case that `/usr/xpg4/bin/` exists only on machines where it is "necessary"?
* I ask because I notice that `/usr/xpg4/bin/` doesn't exist on my Ubuntu machine.
So to sum up, is this a good a idea?
if [ -d "/usr/xpg4/bin" ]; then
#Place XPG directory at beginning of path to always use XPG version of commands
export PATH="/usr/xpg4/bin/:$PATH"
fi
If not, why not?
[1]: https://en.wikipedia.org/wiki/X/Open