9

My question seems to be trivial but I didn't manage to find anything helpful in internet. I have a binary in

/urs/bin/binary

but it is outdated and newer version is available on some mount for example

/mount/new_version/binary

An there's a bash script that invokes this binary in a form like

binary -doSomething

I need this script to invoke new version of binary instead of old one but I'm not permissioned to change this script. Is is a way to somehow override path to it but only for my user? Any help would be appreciated.

1
  • If you are not allowed to do it, talk to your admin.
    – Sven
    Oct 24, 2013 at 12:10

3 Answers 3

11

If the binary is in /usr/bin/binary and the script invokes the binary without specifying the full path, but instead relies on /usr/bin being in PATH then you can simply add the location of the new binary to the beginning of the user's PATH. Put something like this in their ~/.bashrc:

PATH=/mount/new_version:$PATH

For security reasons, scripts often specify the full path to binaries to prevent this kind of thing.

0
3

If you have access to the binary you can backup it and create a symbolic link.

mv /urs/bin/binary /urs/bin/binary.bkp
ln -s /mount/new_version/binary /urs/bin/binary

[EDIT]

Sorry, didn't saw the change must be done for one user only.

You can create a function to be called instead of the binary.

Depending on how you execute the binary (full path or just name) you must create a suitable function, like:

# Full path
function /urs/bin/binary () { command /mount/new_version/binary "$@"; }
export -f /urs/bin/binary
# Name
function binary () { command /mount/new_version/binary "$@"; }
export -f binary

If the binary don't accept/need arguments, remove the "$@".

To automatize the function creation, put the function lines in the .profile file in the user home directory.

2
  • This will affect all users. It's not acceptable. Oct 24, 2013 at 12:22
  • Sorry, I corrected the answer as the change must affect one user only.
    – Douglas P.
    Oct 24, 2013 at 13:56
3

alias commandname=/mount/new_version/binary

in the .bashrc above the path statement/export or in the profile will accomplish easy enough.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .