1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./readlink-demo.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | two-file-symlinks() {
|
11 | # NOTE: Two levels of symlinks requires readlink -f, not readlink.
|
12 | ln -s -f $PWD/demo/readlink-demo-target.sh /tmp/demo.sh
|
13 | ln -s -f /tmp/demo.sh /tmp/demo-level2.sh
|
14 |
|
15 | # Call readlink-demo-target.sh through TWO file symlinks
|
16 | /tmp/demo-level2.sh
|
17 | }
|
18 |
|
19 | dir-symlink() {
|
20 | ln -s -f --no-target-directory $PWD/demo/ /tmp/oil-demo
|
21 |
|
22 | # Calling readlink-demo-target.sh when a PATH component is a symlink to a
|
23 | # directory
|
24 | /tmp/oil-demo/readlink-demo-target.sh
|
25 | }
|
26 |
|
27 | all() {
|
28 | echo 'Two files:'
|
29 | two-file-symlinks
|
30 | echo
|
31 |
|
32 | echo 'Dirs:'
|
33 | dir-symlink
|
34 | echo
|
35 | }
|
36 |
|
37 | "$@"
|