在执行shell脚本的时候 任意目录下执行

#!/bin/bash

echo 'nihao'

cd "$(dirname "$BASH_SOURCE[0]")"

加入最后这句话

原文地址:https://www.cnblogs.com/gzpu/p/13700510.html