What's the equivalent to ${var:-defaultvalue} in fish?

后端 未结 3 934
生来不讨喜
生来不讨喜 2021-01-15 06:26

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

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-15 07:17

    Since ${var:-value} expands to value if $var is empty, you can always replace it by writing your code out the long way:

    begin
      if test -n "$gnupg_SSH_AUTH_SOCK_by"
        set result "$gnupg_SSH_AUTH_SOCK_by"
      else
        set result 0
      end
    
      if [ "$result" -ne %self ]
        set -x SSH_AUTH_SOCK "/run/user/$UID/gnupg/S.gpg-agent.ssh"
      end
      set -e result
    end
    

    Note that I don't use (a) endorse, (b) condone the use of, or (c) fail to hold unwarranted prejudices against users of, fish. Thus, my advice is very much suspect, and it's likely that there are considerably better ways to do this.

提交回复
热议问题