Home > front end >  How to change where the uname command searches for uname?
How to change where the uname command searches for uname?

Time:12-22

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.

CodePudding user response:

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.

CodePudding user response:

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
  • Related