获取路径中包含空格的OS X Shell脚本所在的路径... [英] Getting the path where an OS X shell script is located within the script...when the path has whitespace
本文介绍了获取路径中包含空格的OS X Shell脚本所在的路径...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Bash脚本中使用它来获取运行脚本的路径.必须双击OS X中的.command文件.
I am using this in a Bash script to get the path where I have run the script from. It is necessary for double clicking a .command file in OS X.
#!/bin/bash
BASEDIR=$(dirname $0)
cd $BASEDIR
问题是路径有空格时不起作用.您该如何解决?
The problem is it doesn't work when the path has spaces. How might you fix that?
推荐答案
#!/bin/bash
BASEDIR="$( dirname "$0" )"
cd "$BASEDIR"
这篇关于获取路径中包含空格的OS X Shell脚本所在的路径...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文