How to do it...

  1. Open a terminal, and create the whoami.sh script:
#!/bin/bashVAR=$0echo "I was ran as: $VAR"
  1. Execute whoami.sh and observe what has happened:
$ bash whoami.sh
  1. Next, create a soft link to whoami.sh using the ln command:
$ ln -s whoami.sh ghosts-there-be.sh
  1. Next, run ls -la. Notice any differences?
ls -la ghosts-there-be.sh whoami.sh 
  1. On to hard links, which are created this way using ln:
$ ln ghosts-there-be.sh gentle-ghosts-there-be.sh$ ln whoami.sh real-ghosts-there-be.sh
  1. Next, let's look at the difference in results when running the commands:
$ ls -la ghosts-there-be.sh whoami.sh real-ghosts-there-be.sh gentle-ghosts-there-be.sh lrwxrwxrwx 1 rbrash rbrash 18 Dec 12 15:07 gentle-ghosts-there-be.sh -> ghosts-there-be.sh ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.