2
我已經找到答案,並且what I've found似乎不起作用。如果我運行weather "NYC"
,echo'd行是「weather = NYC」,但是如果我運行weather
,echo'd行是「weather =」。我如何設置$location
的默認值?如何爲命名函數參數設置默認值?
function weather --argument location --description "Display weather information for a given location"
set -q location; or set location "San Francisco, CA"
echo "weather = $location"
curl -H "Accept-Language: en" "wttr.in/$location?u"
end
更新:
我已經能夠出現以下變化所需的行爲,但我仍然感到好奇,如果set -q location; or set location "San Francisco, CA"
應該工作。它似乎在命令行上,但不在函數中。
if not test -n "$location"
set location "Washington, DC"
end