learning shell get script absolute path (3)

Shell get script absolute path

Purpose

       Get shell script absolute path

 

Eevironment

       Ubuntu 16.04 bash env

 

Procdeure

Source code:

1 #!/bin/bash
2 echo "$(dirname "$(realpath "${BASH_SOURCE}")")"
3 echo "$(realpath "${BASH_SOURCE}")"
4 echo "${BASH_SOURCE}"

 

Test method:

vmuser@vmuser-virtual-machine:~/panzidong/shell$ ./tmp.sh 
/home/vmuser/panzidong/shell
/home/vmuser/panzidong/shell/tmp.sh
./tmp.sh

 

posted @ 2019-01-24 14:11  嵌入式实操  阅读(207)  评论(0编辑  收藏  举报