« first day (1080 days earlier)      last day (1319 days later) » 

6:27 AM
hm
 
 
9 hours later…
3:03 PM
@Zanna (unrelated) I don't think that needs to be changed in your answer -- certainly I have answers that I haven't gotten around to editing that carry a far higher risk of misleading readers than that answer of yours -- but unlike with type and command -v, the output of which is unreliable and shouldn't be relied upon. In the case of sh, it's unlikely that anybody would make it an alias or shell function...but readers who know what presumably also know it's /bin/sh.
 
I don't know how to use command -v to find out what sh is
 
command -v sh
 
oh
thanks!
I will try to fix it later
 
I'd generally use type sh or (though it's a Bash-ism) type -a sh. But in that context it seemed you wanted just the output path, which command -v will give. type -p also gives this but it's a Bash-ism (and unlike type -a, it has a portable analogue: command -v).
I'm not sure what the best change actually is, though. On systems where /bin and /usr/bin are merged (with /bin as a symlink to /usr/bin), whichever directory a package tries to install a command into, it is seen as in /usr/bin since that's by default earlier in $PATH. So finding out where stuff like sh, dash, or bash is by running any of those commands doesn't distinguish them from commands whose packages actually try to put them in /usr/bin.
This matters because it used to be that those commands could be used by novices to figure out what hashbang to write. Now that's inadequate because hashbangs like #!/usr/bin/sh are bad -- a script with such a hashbang will fail even on other installations of the same Ubuntu release (since whether /bin and /usr/bin are merged in new releases depends on whether the release was a fresh install or an upgrade from a release on which they were not merged).
Personally I wouldn't use realpath there, since ls shows symlinks with their targets:
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Mar 30 05:45 /bin/sh -> dash
 
3:52 PM
sorry I should have asked you to elaborate back then
was just a bit busy
@EliahKagan oh that is much better hahaha
 
 
2 hours later…
5:40 PM
@Zanna I edited my answer
 
@EliahKagan I prefer file /bin/sh.
 
 
1 hour later…
6:53 PM
@Zanna If not using command substitution, the output needn't just be the path, and then one need not use command -v (or type -p) and can use type or type -a.
@Kulfy Yes, that's also good.
 
Just to add, type is a shell builtin and sh's type doesn't recognise -a.
 
Yes, that's why I keep calling type -a a "Bash-ism".
 
@EliahKagan It can be called as "zsh-ism" too :)
 
Yes, few Bash-isms are truly unique to Bash. :)
 
True that.
 
7:00 PM
But being a shell builtin is itself a benefit. One wants to use a shell builtin finding out what a command is, so that one is not misled into thinking that one is running an external command that one is not running (or that one is automatically running with various options). That's the benefit of type and command -v over which.
(which is also non-portable, with different GNU/Linux systems whiches working differently, some even attempting to guess at how shells behave with a command. So in general that's another benefit of type and command -v, though not of type -a or type -p, over which. But that's not what I've been talking about since I don't think it's inherently a flaw for techniques shown on Ask Ubuntu to depend on things about Ubuntu.)
Note that this--wanting a shell builtin--doesn't apply to ls, find, and realpath which are fine because one uses them for something quite different (turning something that is already a path into information about the thing it is a path to).
I should mention that realpath does have one advantage (though sometimes it is a disadvantage): it navigates multiple symbolic links. For example, compare the output of file /usr/bin/editor and ls -l /usr/bin/editor to realpath /usr/bin/editor.
I'll move some messages to the Island soon btw.
 
I remember once my friend's PC gave some output for which foo but no output for type foo. ¯\_(ツ)_/¯
 
@Kulfy If it was a Bourne-style shell, then that sounds like it was a situation where it was good that they tried type. The output of which when type doesn't finding anything is almost always wrong or at least misleading.
 
@EliahKagan Yeah. That's why I usually prefer type over which and whereis.
 
7:22 PM
35 messages moved from Raiders of the Lost Downboat
 

« first day (1080 days earlier)      last day (1319 days later) »