Create folder in same directory as shell script

This question already has an answer here:

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

  • You could try this one liner:

    DIR="$( cd "$( dirname "$0" )" && pwd )
    

    Will leave you with a $DIR variable that contains the full path to the current directory. See this answer for more information!


    script_dir=$(dirname "$0")
    

    $0 is the name of the running script, as entered on the command line (for example: ./bin/script )

    If you want the full path:

    script_dir=$(cd -P -- "$(dirname "$0")" && pwd -P)
    
    链接地址: http://www.djcxy.com/p/9754.html

    上一篇: 查找执行的命令的位置

    下一篇: 在与shell脚本相同的目录中创建文件夹