Search code examples
fish

Valuable changes depends on the existence of argument file


I wrote configuration of fish shell like this:

# One or more argument(s) will be given
function run
    set -l src $argv[1]
    set -l var
    switch "$src"
        case *
            set var "$src"
    end
    echo $var
end

I expected the first argument is printed in any case if one or more argument is given. However, $var becomes $argv[1] if file with the same name as $argv[1] exists, otherwise it becomes empty string.

Could someone tell me why?


Solution

  • The * in case * is interpreted as a glob. Quote it if you do not want that.