by danso in this thread (who talked about cp and mv), that I learned, from the K&P book (IIRC), that the commands cp, mv and ln were actually all links to the same executable, which did the right thing based on what name it was invoked by, as found from looking at argv[0]. Checked just now in Linux with:
cd /usr/bin
ls -li cp mv ln
on SuSE Linux, but they seem to be different files now ...
Well, if you "want" that, you could also have a look at busybox -- which does cp,ls,mv and more -- in a single binary (optionally statically linked).
I actually tend to do a switch on the first argument for certain shell scripts, such as this little thing for switching between single display on a couple of laptops/netbooks:
#!/usr/bin/env sh
INTERNAL=LVDS
EXTERNAL=VGA-0
for monitor in `xrandr|grep connected|awk '{ print $1 }'`
do
case "${monitor}" in
"LVDS")
INTERNAL="LVDS"
;;
"DFP1")
EXTERNAL="DFP1"
;;
"CRT1")
EXTERNAL="CRT1"
;;
"VGA-0")
EXTERNAL="VGA-0"
;;
esac
done
twoscreen()
{
xrandr --output ${EXTERNAL} --auto --rotate normal --pos 0x0 \
--output ${INTERNAL} --auto --rotate normal --pos 768x1152
}
vgaonly()
{
xrandr --output ${EXTERNAL} --auto --rotate normal --pos 0x0 \
--output ${INTERNAL} --off
}
laptoponly()
{
xrandr --output ${INTERNAL} --auto --rotate normal --pos 0x0 --output ${EXTERNAL} --off
}
fn=`basename "$0"`
case $fn in
"twoscreens")
twoscreen
;;
"onescreen")
laptoponly
;;
"vgaonly")
vgaonly
;;
*)
echo "Usage: vgaonly|onescreen|twoscreen"
echo "called as: $0 ($fn)"
;;
esac
As a side note, for those running Debian (or Ubunut, I think) there's a couple of utilities to help search for binaries/files -- namely apt-file and dlocate. Eg:
apt-file search -F bin/cp #returns coreutils
# -F does a fixed string search, otherwise you'll
# get a list of all packages which contains files
# that *contain* bin/cp in their name such as:
# passwd: /usr/sbin/cpgr
Dlocate works with regular expressions and an index, so it's much faster and you can do:
>if you "want" that, you could also have a look at busybox
Don't want or need it, just mentioned it as an interesting bit of Unix history. I guess the 3 files are not links but separate files nowadays due to much cheaper and more plentiful disk space compared to those days.
Your script is interesting.
Didn't know about apt-file or dlocate, good to know, thanks.
I was reminded, by this comment:
https://news.ycombinator.com/item?id=7036920
by danso in this thread (who talked about cp and mv), that I learned, from the K&P book (IIRC), that the commands cp, mv and ln were actually all links to the same executable, which did the right thing based on what name it was invoked by, as found from looking at argv[0]. Checked just now in Linux with:
cd /usr/bin ls -li cp mv ln
on SuSE Linux, but they seem to be different files now ...
The -i option to ls shows the inode number.