简体   繁体   English

将多个项目附加到fish shell中的路径(相当于:+ =)

[英]Append multiple items to path in fish shell (equivalent to: +=)

For example chruby has a user define additional ruby paths via. 例如, chruby有一个用户通过定义额外的ruby路径。 the following: 下列:

RUBIES +=( /opt/jruby-1.7.0 "$HOME/src/rubinius" ) RUBIES + =(/ opt / jruby-1.7.0“$ HOME / src / rubinius”)

Is there a nice way to accomplish this in fish? 在鱼中有没有很好的方法来实现这一目标?

All fish variables are arrays. 所有鱼类变量都是数组。 So in theory this would be as simple as 所以理论上这就简单了

set -x RUBIES $RUBIES /opt/jruby-1.7.0 "$HOME/src/rubinius"

Unfortunately fish won't automatically convert that array to a string of colon separated values when it exports the var. 不幸的是,当导出var时,fish不会自动将该数组转换为一串冒号分隔值。 At the present time fish only does that for PATH and MANPATH. 目前,鱼只为PATH和MANPATH做到了。

You can do it like this: 你可以这样做:

set -x RUBIES "$RUBIES:/opt/jruby-1.7.0:$HOME/src/rubinius"

But that assumes RUBIES has already been set; 但是,假设RUBIES已经确定; otherwise you get a string with a leading colon which may, or may not, have special meaning for any software using the var. 否则你得到一个带有前导冒号的字符串,对于使用var的任何软件,它可能有也可能没有特殊含义。 Dealing with that is straightforward: 处理这个很简单:

if set -q RUBIES[1]
    set -x RUBIES "$RUBIES:/opt/jruby-1.7.0:$HOME/src/rubinius"
else
    set -x RUBIES "/opt/jruby-1.7.0:$HOME/src/rubinius"
end

Too, if you're using fish 2.3 (soon to be released) or a fish built from git head you can use the new "string" builtin to split and join the string on colons: 太,如果你正在使用鱼2.3(即将被释放)或从git head构建的鱼,你可以使用内置的新“string”来分割和连接冒号上的字符串:

set rubies (string split ':' $RUBIES)
set rubies $rubies /opt/jruby-1.7.0 "$HOME/src/rubinius"
set -x RUBIES (string join ':' $rubies)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM