A few days ago wrote seven bull demo, with Bash wrote a convenient installation of the script, involving the path-related judgments, from StackOverflow, plus their own practice to tidy up.
Simple version
The following is one of the simplest implementations that can solve most of the problems that are displayed for soft links in the directory where the soft links are located
Lineos:false
Copy Code code as follows:
#!/bin/bash
Dir= "$ (CD" $ (dirname "$") "&& pwd"
Perfect version
This release solves the problem of using ln-s target linkname to create soft links that do not correctly take the real script.
Lineos:false
Copy Code code as follows:
#!/bin/bash
Source= "$"
While [-H "$SOURCE"]; Do # resolve $SOURCE until the ' file is no longer a symlink
Dir= "$ (cd-p" $ (dirname "$SOURCE") "&& pwd)"
Source= "$ (readlink" $SOURCE ")"
[[$SOURCE!=/*]] && source= "$DIR/$SOURCE" # If $SOURCE is a relative symlink, we need to resolve it relative To the path where the Symlink file is located
Done
Dir= "$ (cd-p" $ (dirname "$SOURCE") "&& pwd)"