Bash and zsh has this ${VAR:-1} easy way to set a default value, when $VAR is defined ${VAR:-1} will return the value of $VAR, and when $VAR is not defined, ${VAR:-1} will return the fallback default value -1, like:
$ echo ${VAR:-1} -1 $ export VAR=15 $ echo ${VAR:-1} 15 This is very useful when define a function with default parameter, like: hello() { echo Hello ${1:-World}! } But fish doesn't support his trick, and there is no easy equivalent. I'm thinking about defining a function to support this feature. This is my implementation: function fbd --description "Use second arg's vlaue as the fallback\ default value if the first arg is not defined" echo $argv[1] end This function always output the first valid argument, so if the first argument passed into fbd is not defined, the second argument will be first valid argument: $ fbd $VAR 1 1 $ set VAR 15 $ fbd $VAR 1 15 I just used fish for 1 week, I'm not sure if this fbd function has any issue, or if there is a better way to implement in fish, please comment. ------------------------------------------------------------------------------ DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access Free app hosting. Or install the open source package on any LAMP server. Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users