要使用shell脚本获取当前目录,可以使用内置的环境变量PWD
或者$(pwd)
命令来获取当前工作目录。以下是两种方法:
PWD
:current_dir=$PWD
echo "当前目录是:$current_dir"
$(pwd)
命令:current_dir=$(pwd)
echo "当前目录是:$current_dir"
以上两种方法都会获取当前shell所在的工作目录,并将其赋值给变量current_dir
,然后打印出来。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:怎么用shell脚本获取当前目录名称