Mac OS X:如何使终端在.command文件所在的目录中打开?
我正在尝试制作脚本文件来从集市服务器推送、拉取我的项目等。在 Linux 中,我只是将 bzr 命令放入 .sh 文件中,使其可执行并且有效。但在 Mac 中,当我将 bzr 命令放入 .command 文件中时,终端会在我的主文件夹中打开,并且命令会在那里运行。这显然不是我的意图。所以我发现,要在我想要的文件夹中运行,我首先必须 cd 到该文件夹。虽然这是有效的,但我希望脚本是通用的,这样如果我只是将其复制到一个文件夹中,它就会在该文件夹中使用命令提示符运行。有没有更好的方法来做到这一点,或者我是否必须不断更改所有项目脚本中的 cd 命令?
I am trying to make script files to push, pull etc my project from the bazaar server. In linux, i simply put the bzr commands in a .sh file , made it executable and it worked. But in Mac , when i put the bzr commands in a .command file, the terminal opened at my home folder and the commands were run there. which is obviously not what i intended. So what i found out was that to run in the folder i want, i first had to cd to this folder. Although this is working, but i want the scripts to be generic so that if i just copy it into a folder and it would run with the command prompt at that folder. Is there a better way to do this or would i have to keep changing the cd command in the scripts for all my projects??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
cd "$(dirname "$0")" 启动脚本
Start the scripts with
cd "$(dirname "$0")"