Why doesn't this work in bash, but does in zsh?

#!/usr/bin/env bash

a=$(tput cols)
b=$(( a - 4 ))
c=$(seq $b $n | xargs printf '*%.0s')
echo $c

Change the bash to zsh and it works, baffled!!

It should return:


Bash returns a huge list of files and then screws up.

This works both in Bash and Zsh:

#!/usr/bin/env zsh
printf -v BAR '%*s' $(tput cols) ' '
printf '%s' "${BAR// /*}"
1 Like

Just add


to the beginning of your script. It should then work in both shells.

Bash will treat * as GLOB/wildcard, and because of how subshell/expansion works it will return a list of files and folders from current directory as output.


Thanks guys, it was late and my brain was befuddled :rofl:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.