익명 07:31

/usr/local/bin/apt-get script being completely ignored

/usr/local/bin/apt-get script being completely ignored

I have added a script to /usr/local/bin/apt-get on an Ubuntu Trusty system which does some checking that is required before launching the "official" apt-get.

For reasons I simply cannot comprehend this script is completely ignored despite everything telling me that it shouldn't be.

For testing purposes the script currently does nothing and should simply exit, but it is never launched anyway.

/usr/local/bin has priority in the $PATH:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ which apt-get
/usr/local/bin/apt-get
$ ls -l /usr/local/bin/apt-get
-rwxr-xr-x 1 root root 553 Apr 16 03:01 /usr/local/bin/apt-get

strace appears to execute the script:

$ strace apt-get
execve("/usr/local/bin/apt-get", ["apt-get"], [/* 26 vars */]) = 0
[...]
open("/usr/local/bin/apt-get", O_RDONLY) = 3
[...]
read(10, "#!/bin/sh\n\n# Note: this little s"..., 8192) = 553

Yet the script is clearly being ignored:

$ apt-get
apt 1.0.1ubuntu2 for amd64 compiled on Oct 28 2014 20:55:14
Usage: apt-get [options] command
...

Launching /usr/local/bin/apt-get directly exits silently, as it should, so the script itself is executable and works correctly.

Could this be a hidden security setting that I know nothing about?



Top Answer/Comment:

The solution is hash -r.

Bash keeps a cache of binaries (or scripts, etc.) that it has found and used, and doesn't update automatically.

A new session, such as over SSH or a new terminal, will run with a clean ${BASH_CMDS} and will have to find the relevant binary again from the ${PATH}.

Use echo ${BASH_CMDS[*]} to see the list in the current terminal.

Source: man bash

상단 광고의 [X] 버튼을 누르면 내용이 보입니다