Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fish is treating bash script as a fish script

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading