要使用shell脚本获取当前目录,可以使用内置的环境变量PWD或者$(pwd)命令来获取当前工作目录。以下是两种方法:
PWD:current_dir=$PWDecho "当前目录是:$current_dir"使用$(pwd)命令:current_dir=$(pwd)echo "当前目录是:$current_dir"以上两种方法都会获取当前shell所在的工作目录,并将其赋值给变量current_dir,然后打印出来。
要使用shell脚本获取当前目录,可以使用内置的环境变量PWD或者$(pwd)命令来获取当前工作目录。以下是两种方法:
PWD:current_dir=$PWDecho "当前目录是:$current_dir"使用$(pwd)命令:current_dir=$(pwd)echo "当前目录是:$current_dir"以上两种方法都会获取当前shell所在的工作目录,并将其赋值给变量current_dir,然后打印出来。