【转载】利用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$

posted @ 2013-08-21 11:32  摩斯电码  阅读(1617)  评论(0编辑  收藏  举报