How can I alias a binary dependent on the machine I am on

0

I work on different machines, some as centos7, some are centos6, I build a binary tmux with a different version on each 'type' as the same version cannot runn both.

How can I tell my .bashrc to switch between version of tmux depending on what box I work on ?

statquant

Posted 2017-01-15T18:10:52.867

Reputation: 195

Answers

1

The command uname -m will tell you what architecture you are on. For example, on my system right now:

$ uname -m
x86_64

I might suggest putting archful binaries into ~/bin/i686 and ~/bin/x86_64. (Or, if it's 32-bit Power or something else, whatever uname -m returns.) Then, in ~/.bash_profile (which is the right place for this, have a line like this:

PATH=$PATH:~/bin/$(uname -m)

which will append this new arch-specific bin path to your existing path.

Or, if you want something other than the machine architecture, use a different distinguisher. For example, an easy way to tell CentOS versions is to look at the version of the centos-release package, with rpm -q, so, like this:

PATH=$PATH:~/bin/centos$(rpm -q --qf '%{VERSION}' centos-release)

which will get you either ~/bin/centos6 or ~/bin/centos7 — although there's no error handling, so on Fedora or something you'll get a nonsensical error message right in the path. (Maybe check for whether centos-release exists with an if statement before even running this.)

You can also add --nosignatures --nodigest to speed up this RPM command by a few hundredths of a second. Not a big deal, but since it'll happen at every new login shell, seems worth the extra typing.

mattdm

Posted 2017-01-15T18:10:52.867

Reputation: 2 324

There is a slight misunderstanding here, both are 64bit, it is the version of centos that differs, still +1 – statquant – 2017-01-15T22:37:20.680

Oh, I see. In that case, same basic concept but use a different distinguisher. – mattdm – 2017-01-15T22:47:48.010