I have a bash script like bellow:
#!/bin/bash
# create-multiple-chapters {1..5}
# create-multiple-chapters {1,2,5}
for i in $*; do
mkdir chapter${i}
touch chapter${i}/init.adoc
done
It create multiple directories with file. I understand that fish does not support the {x..y} range expansion syntax. However, this is a bash script. Still when I run this script from fish shell like create-multiple-chapters {1..5}, it only create one directory named chapter{1..5}. Why is that?
>Solution :
The problem is that you think the argument {1..5} is expanded by this line of your script:
for i in $*; do
In fact, that is an incorrect assumption. When your inteactive shell is Bash, and you type create-multiple-chapters {1..5} at the command line, it is the interactive shell itself that does the expansion, and turns the command line into create-multiple-chapters 1 2 3 4 5. The Bash script then processes each of these five arguments in the loop.
Fish doesn’t do this expansion. Instead, if you are running fish, you need to use the seq command to do the expansion and pass the expanded arguments to your Bash script.