Shell – making directories – Shell script has different outcome then Shell

I am trying to make a shell script that makes directories numbered from 01-13.

I use command mkdir -p test/file{01..13}

when I run command via shell script it names directories as 1,2,..,13 but when I use the command in shell itself, it names it correctly as 01,02,..,13. (see image below)

Is there a way to fix this?

enter image description here

>Solution :

Your interactive shell is zsh, but you run the script with sh. To run your script with zsh, call zsh

Alternatively, and recommended, add a shebang line to your script: #!/bin/zsh and mark it executable with chmod u+x Then you can execute it with just ./ and it will be executed with the right shell automatically.

Leave a Reply