Trying fish, I am stuck on equivalents for some of the variable expansions from bash:


How do I do that in fish?

1 Answer 1


Nothing so short as that posix shell variable expansion:

if set -q this; or test -z $this
    set x $that
    set x $this

or the "terse" version

begin; set -q this; or test -z $this; end; and set x $that; or set x $this

(I'll be happy to be proven wrong about this one)

  • Sorry you've answered a slightly more complicated question than I intended to ask :-) I intended the question as two separate examples, I should have split it into 2 code sections. Aug 11, 2020 at 12:36
  • I don't think I did. This is what the sh ${var:-default} expansion does: if the variable var is unset or empty, return the default value, else return the variable's value. This only difference in your two examples is set x $that versus set x "that" Aug 11, 2020 at 13:25
  • Ah, I see what you mean. So now I probably want to understand why you prefer set -q this; or test -z $this over test -z "$this" which would also deal with the two cases? Aug 11, 2020 at 13:52
  • 1
    I was just being super explicit about the exact translation. Because in bash you can say ${this-$that} that only returns the default value if the variable is unset -- if $this is set but empty, that's what you get Aug 11, 2020 at 13:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .