$(cd "$(dirname "$0")",pwd) 解析

xx.sh 文件内容如下:

#!/bin/bash
BIN_FOLDER=$(cd "$(dirname "$0")";pwd)
echo $BIN_FOLDER
PROJECT_FOLDER=$(cd "$(dirname "$BIN_FOLDER")";pwd)
echo $PROJECT_FOLDER
PYTHON_BIN=$PROJECT_FOLDER/.venv/bin/python
echo $PYTHON_BIN

BIN_FOLDER = $(cd "$(dirname "$0")",pwd) 解析:

1、取当前运行脚本的所在路径: $0

2、取当前脚本所在路径的父目录: dirname "$0"

3、取返回的父目录的值: $(dirname "$0")

4、cd到返回的父目录: cd "$(dirname "$0")"

5、输出地址: cd "$(dirname "$0")",pwd

6、取输出的地址,并赋值给BIN_FOLDER: BIN_FOLDER = $(cd "$(dirname "$0")",pwd)

posted @ 2019-02-20 18:48  turbolxq  阅读(4907)  评论(0编辑  收藏  举报