鱼中的$ {var:-defaultvalue}等于什么? [英] What's the equivalent to ${var:-defaultvalue} in fish?

查看:132
本文介绍了鱼中的$ {var:-defaultvalue}等于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在尝试将.bashrc转换为fish格式,几乎已经完成,大部分在文档中都很清楚,但这部分让我头疼..因此我的gnupg可与yubikey ssh等配合使用. 鱼版本是Arch GNU/Linux下最新的3.0版本.

Hello I am trying to translate my .bashrc to fish format almost done, mostly is clear on the documentation but this part is giving me a headache.. is so my gnupg works with my yubikey ssh etc etc.. The fish version is latest 3.0 under Arch GNU/Linux

BASH上的原始内容:

original on BASH:

# Set SSH to use gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
  export SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh"
fi
echo "UPDATESTARTUPTTY" | gpg-connect-agent > /dev/null 2&>1

我的一半变成了鱼:

set -e SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]
  set -x  SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh"
end
echo "UPDATESTARTUPTTY" | gpg-connect-agent > /dev/null 2>&1

因此,如您在上面看到的那样,到目前为止,我已经将stdin和stderror pine和unset变量设置为set -e,我所遇到的错误对我来说有些晦涩:

so as you see above I have so far converted the stdin and stderror pine and the unset variable with set -e the error I am having is a bit more obscure to me:

~/.config/fish/config.fish (line 33): ${ is not a valid variable in fish.
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]
       ^
from sourcing file ~/.config/fish/config.fish
        called during startup

任何帮助将不胜感激, BTW也将是一个不错的迁移:)那边有吗?

Any help will be much appreciated, BTW will be nice a migrate too :) are there any out there?

[edit]好的工作要归功于下面的响应,现在我所有的bash环境,配置文件,bashrc等都被翻译成fish了,并且仅用作我的shell 100%

[edit] ok got this working thanks to the response below, now all my bash environment, profile, bashrc etc is translated to fish and using it solely as my shell 100%

推荐答案

除非您对fish的语法和行为有更好的了解,否则不应该更改登录shell.例如,在鱼中,$$的等效项是%self$fish_pid,具体取决于您使用的鱼的版本.您应该始终指定遇到问题的程序的版本.

You should not change your login shell until you have a much better understanding of fish syntax and behavior. For example, in fish the equivalent of $$ is %self or $fish_pid depending on which fish version you are using. You should always specify the version of the program you are having problems with.

假设您使用的是Fish 2.x,将其写为

Assuming you're using fish 2.x that would be written as

if not set -q gnupg_SSH_AUTH_SOCK_by
or test $gnupg_SSH_AUTH_SOCK_by -ne %self
    set -gx SSH_AUTH_SOCK "/run/user/$UID/gnupg/S.gpg-agent.ssh"
end

此外,请注意set -x中的var名称和值之间没有等号.

Also, notice that there is no equal-sign between the var name and value in the set -x.

这篇关于鱼中的$ {var:-defaultvalue}等于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆