I'm studying the RBENV codebase, and I see that on line 116 of the rbenv-init
file, a function is created which contains a switch
statement. My hypothesis is that we check whether the value of the command
variable is one of the members of the array of values in the commands
(plural) variable. If it is, we execute branch 1 of the switch statement. Otherwise, we execute branch 2.
I wanted to write a simple script to test my hypothesis, so I wrote the following:
#!/usr/bin/env fish
set command "foo"
switch $command
case ${argv[*]}
echo "command in args"
case "*"
echo "command not found"
end
However, when I run this script, I get the following error:
$ ./foo bar baz
./foo (line 6): ${ is not a valid variable in fish.
case ${argv[*]}
^
warning: Error while reading file ./foo
I was expecting argv
to evaluate to an array containing bar
and baz
, since those are the two args I provide to the script. My syntax matches that of line 117 in the source code (i.e. case ${commands[*]}
).
The shell I'm executing the script in is zsh v5.8.1, however my shebang specifically references the 'fish' shell so I'd think my shell wouldn't matter. I have fish v3.5.1 installed, fwiw.
$
are prefixed with one, and then make it to the fish code and some aren't which means they're expanded (by bash) before making it to the fish code.