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.

Viktor Stolbin
  • 211
  • 1
  • 2
  • 9

3 Answers3

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.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
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.

Douglas P.
  • 71
  • 2
3

alias commandname=/mount/new_version/binary

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

squillman
  • 37,883
  • 12
  • 92
  • 146
art3mis
  • 1,008
  • 9
  • 4