如何设置当前工作目录到脚本的目录? [英] How to set current working directory to the directory of the script?

查看:136
本文介绍了如何设置当前工作目录到脚本的目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个bash脚本。我需要的当前工作目录始终是该脚本所在的目录。

默认行为是在脚本中的当前工作目录是我从中运行它的外壳,但我不希望这种行为。


解决方案

 #!/斌/庆典
CD$(目录名称$ 0)

I'm writing a bash script. I need the current working directory to always be the directory that the script is located in.

The default behavior is that the current working directory in the script is that of the shell from which I run it, but I do not want this behavior.

解决方案

#!/bin/bash
cd "$(dirname "$0")"

这篇关于如何设置当前工作目录到脚本的目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆