【转载】利用shell脚本获取一个文件的绝对路径readlink

转载自:http://os.chinaunix.net/a2007/1118/976/000000976787.shtml

#! /bin/bash

    echo "Path to $(basename $0) is $(readlink -f $0)"

可以看一下执行结果:

pengdl@localhost:~/test/shell$ ls
sh1.sh
pengdl@localhost:~/test/shell$ ./sh1.sh
Path to sh1.sh is /home/pengdl/test/shell/sh1.sh
pengdl@localhost:~/test/shell$

原文地址:https://www.cnblogs.com/pengdonglin137/p/3272290.html