bash 设置脚本的工作目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42588656/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:50:58  来源:igfitidea点击:

Set working directory for script

bash

提问by A. Galloway

I have a script in /A/B/script.sh. When called, it needs to operate on files in /X/Y/Z. How can I set a working directory specifically forthe script, inthe script?

我在 /A/B/script.sh 中有一个脚本。调用时需要对/X/Y/Z中的文件进行操作。如何设置工作目录专门剧本,剧本?

采纳答案by Joseph Sible-Reinstate Monica

Put a cdstatement in the script, just like you'd type to set your working directory from an interactive bash shell.

cd在脚本中添加一条语句,就像您在交互式 bash shell 中键入以设置您的工作目录一样。