Xiphias Xiphias - 3 months ago 15
Bash Question

Why does brace expansion not work like a loop in this fish (shell) case?

I would expect these commands to behave identically:

# 1
python3 scripts/{01,02}*.py

# 2
for script in scripts/{01,02}*.py; python3 $script; end


The fact that #1 returns a single line if run with
echo
instead and #2 returns two makes me believe that there is a difference. The second version works, the first only runs the first script.

Why is that?

Answer

I'm not familiar with fish but at first sight, in the first case, you are running one instance of the python interpreter passing as first argument the script to execute and as second argument (first argument passed to the first script which it might well ignore) the name of the second script.

In the second case, you are running two instances of the python interpreter, each one with the name of a script to be executed.

It's no surprise the outcome is different.