News for hackers. Stuff that matters.
Re:Demystifying the (Shebang): Kernel Adventures by lelandfe on Thursday April 10, 2025 @03:43PM (#43647389)
> Since I never remember which one is which, a good way to check is using the utility `file`: `file $(which useradd)`

While we're here, can someone explain why `which` prints some locations, and for others the whole darn file? Like `which npm` prints the location; `which nvm` prints the whole darn file.

Re:Demystifying the (Shebang): Kernel Adventures by awbraunstein on Thursday April 10, 2025 @03:51PM (#43647455)
`nvm` isn't a file, it is a bash function defined in some file (likely ~/.nvm/nvm.sh). So when you say `which nvm` it prints out the definition of the `nvm` function. This is setup when you added something like:

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. 
 "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
to your bashrc.
Re:Demystifying the (Shebang): Kernel Adventures by YardenZamir on Thursday April 10, 2025 @03:51PM (#43647452)
I can't say the reason, but i can note the pattern. If it's something in your path, like a program or a script which will show you where it is. If it's a shell function sourced you will see the whole thing.

If you write a function in your current session for example which will show you the content of that command. If you write that command in a file and put that file in your path which will show you where it is

Re:Demystifying the (Shebang): Kernel Adventures by cstrahan on Thursday April 10, 2025 @03:53PM (#43647472)
Are you sure that what is being printed is the contents of a file? And which shell are you using?

If your which command is a shell builtin, and nvm is a function, then you’re likely seeing the content of that function.

Re:Demystifying the (Shebang): Kernel Adventures by AlienRobot on Thursday April 10, 2025 @03:52PM (#43647461)
That sounds odd. Try using command -v instead?
Re:Demystifying the (Shebang): Kernel Adventures by adrianmonk on Thursday April 10, 2025 @06:34PM (#43648647)
For this situation, in bash, use 'type nvm' (instead of 'which nvm' or 'file nvm'). It will tell you what 'nvm' is (executable, shell alias, shell function, shell builtin, etc.), which will probably solve the mystery.