4

Today I started to notice weird behavior running a local command for a binary installed through Go. It seems the command is aliased, but consulting alias, it isn't.

The command buf somehow executes cp!

buf --help
Usage: cp [OPTION]... [-T] SOURCE DEST
  or:  cp [OPTION]... SOURCE... DIRECTORY
  or:  cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.

Bash setup

GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu) on Debian GNU/Linux 12 (bookworm).

I use Oh My Bash for fancy stuff with auto-updates enabled. This is my .bashrc:

case $- in
  *i*) ;;
    *) return;;
esac

export OSH='/home/tim/.oh-my-bash'

OSH_THEME="font"

completions=(
  git
  ssh
  go
  docker
  docker-compose
  makefile
)

aliases=(
  general
)

plugins=(
  git
  bashmarks
)

source "$OSH"/oh-my-bash.sh

export PATH="$PATH:/home/tim/.local/bin"

eval $(thefuck --alias)

export BUN_INSTALL="$HOME/.bun"
export PATH=$BUN_INSTALL/bin:$PATH

Failing command

The command was installed in GOPATH using the go command:

go install github.com/bufbuild/buf/cmd/[email protected]

GOPATH:

go env GOPATH
/home/tim/go

And the Go bin directory is part of PATH:

echo $PATH
/home/tim/.bun/bin:/home/tim/go/bin:/home/tim/Repositories/goroot/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/tim/.local/bin:/home/tim/.local/bin

And a sanity check with which resolves to the correct binary:

which buf
/home/tim/go/bin/buf

Executing the path directly works as expected:

/home/tim/go/bin/buf --help
The Buf CLI
...

Configured Aliases

There is no configured alias for buf:

alias buf
bash: alias: buf: not found

Other notes

I've installed Debian just a few months ago. I'm not sure if I ever tried to run buf directly after that. However, my home directory was restored from a backup created from OpenSUSE, on which I'm sure I've run the buf command successfully. Oh My Bash, the Go installation and go binaries were both part of that backup. Most stuff did get updated meanwhile, but I don't remember changing any config.

Other Go binaries work as expected:

cobra-cli --help
Cobra is a CLI library for Go that empowers applications.

For my daily work buf is also used, but through a MakeFile. When invoked through make it runs just fine.

How can the buf command executed cp when I can't find an alias and the PATH is the correct one? Are there other ways of aliasing commands I'm not aware of?

3
  • 13
    Show output of type -a buf Commented 2 days ago
  • On my system buf --help says The Buf CLI A tool for working with Protocol Buffers and managing resources on the Buf Schema Registry (BSR) so there is an issue in your setup most likely. Commented 2 days ago
  • 2
    On your system buf might be a function or something earlier in $PATH. Commented 2 days ago

1 Answer 1

9

As noted in the comments, use type buf to ask the shell what it thinks buf is. In this case, I'd expect you'll find that it is indeed a function as also suggested in the comments - in particular, this function from oh-my-bash:

#   buf:  back up file with timestamp
#   ---------------------------------------------------------
function buf {
  local filename filetime
  filename=$1
  filetime=$(date +%Y%m%d_%H%M%S)
  cp -a "${filename}" "${filename}_${filetime}"
}
4
  • The user would use unset -f buf to undefine the function, which would then give them access to the buf executable instead (in that shell session).
    – Kusalananda
    Commented 2 days ago
  • I did consider suggesting something like alias buf='command buf' to keep both accessible, but then I figured I don't know if oh-my-bash uses the function for something internally and was too lazy to check further
    – muru
    Commented 2 days ago
  • Also command -V buf can be used. For example, mksh R59 has type as an alias for '\\builtin whence -v', whereas command is a shell builtin. One could do, for example, unalias type in mksh to render it inaccessible. Commented yesterday
  • Oh-my...! That was indeed not a direction I was looking. Using type buf answers my question about finding out the source of the alias-like behavior. For now I'll just run command buf when I need it.
    – Tim
    Commented yesterday

You must log in to answer this question.

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