How to change where the uname command searches for uname?

517 Views Asked by At

I need help with loading software that has a built-in platform_check script. My plan is to create a script titled uname which when executed will print an accepted platform. The script works as I need it to but I can't figure out how to get the uname command to search for my custom uname script instead of the /bin/uname default. I have tried using PATH something like PATH=~/.../path_to_uname:$PATH this does not work. I do not have root access so I cant just edit/create uname in its default location.

when I execute the script like so: exec /directory_to_uname/uname and /directory_to_uname/uname -r both work as I intend them I just need to trick the shell to look for my custom uname.

3

There are 3 best solutions below

2
On

You can try to use alias to trick the shell. For example (using bash) edit ~/.bashrc and add alias uname='path/to/uname uname'. execute source ~/.bashrc and the command uname will get the one from alias. If you change it for alias uname='ls -lha' and load (source command) when executing uname it will list the files/dir.

0
On

Assuming you have a platform check script that is calling uname as such, let's call it test.sh:

#!/bin/bash
uname

Initial run shows uname as expected:

user@computer:~$ ./test.sh 
Linux

Export uname as a bash function to echo what you want to use for trickery:

user@computer:~$ function uname {
> echo "hello"
> }
user@computer:~$ export -f uname
user@computer:~$ ./test.sh 
hello
0
On

In order to know which files are accessed/used during a command, you can use the strace command:

strace -y uname

You'll get a whole bunch of files and processes which are used, and you might see if any can be adapted to your needs.

This, however, is quite dangerous (who knows what might be the side-effects?) therefore I would advise you creating and alias for the uname command.