开发者

How to export environment variables with spaces?

开发者 https://www.devze.com 2023-04-12 06:53 出处:网络
I want to set an environment variable that has space in it. It is a path to a folder and the folder name is:

I want to set an environment variable that has space in it.

It is a path to a folder and the folder name is:

/home/mehrabib/my video

I edit .bashrc and add the following line to it:

export $VIDEO=/home/mehrabib/my\ video

and run these commands:

echo $VIDEO
cd $VIDEO
开发者_Python百科

The result is:

/home/mehrabib/my video
/home/mehrabib/my :no such file or directory

I change it to

export $VIDEO=/home/mehrabib/my\\\ video

and run these commands:

echo $VIDEO
cd $VIDEO

The result is:

/home/mehrabib/my\ video
/home/mehrabib/my\ :no such file or directory

What should I do?


You should do

export VIDEO="/home/mehrabib/my video"

and to sum Dan's comments up also do

cd "$VIDEO"

which will expand to

cd "/home/mehrabib/my video"

again.

Personally, I've come to prefer the ${VIDEO} syntax.


You can also substitute special characters - use * as a wildcard to substitute for the space.

VIDEO="/home/mehrabib/m*o"


Try to quote VIDEO: cd "$VIDEO".

0

精彩评论

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

关注公众号