how to echo the path of the script executed from another location?

This question already has an answer here:

  • Getting the source directory of a Bash script from within 50 answers

  • 使用这个脚本。

    #!/bin/bash
    current_location=$(pwd)
    script_location=$(dirname $0)
    if [ $script_location= '.' ]
    then
     script_location="$current_location"
    fi
    echo $script_location
    
    链接地址: http://www.djcxy.com/p/9762.html

    上一篇: 获取脚本被调用的路径

    下一篇: 如何回显从另一个位置执行的脚本的路径?