开发者

how do I escape spaces in $HOME in a bash script?

开发者 https://www.devze.com 2023-02-19 17:09 出处:网络
I\'m trying to run a script which uses my $HOME variable to set things up (it\'s gitolite, by the way).

I'm trying to run a script which uses my $HOME variable to set things up (it's gitolite, by the way).

However, it's failing because I'm on a system where the home directory path has spaces in it.

I want to hack the gitolite bash script at a single point so $HOME turns into something it can work with -- it gets used several times in the script and beyond, and in some places is concatenated to form subfolders, so wrapping it in "" won't work.

So to clean it up I need to say something like:

$HOME=(magic here)$HOME

(This is of course assuming that 开发者_StackOverflow社区the perl scripts that come later don't also read the $HOME variable direct and also need fixing...)


Use quotes everywhere.

HOME="/Users/Foo Bar"
WORKDIR="$HOME"/Work
PLAYDIR="$HOME"/Games
MARATHONDIR="$PLAYDIR"/Marathon


Try this:

export HOME=`echo $HOME | sed -e "s/ /\\ /g"`

Hope that works for you!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号