What are your $1 and $2 argument values?
On my Mac, I can run your two commands as:
Code: Select all
VAR=$(convert lena.jpg -colors 256 -depth 8 -format "%c" histogram:info: | sort -r -k 1 | head -n 16 | grep -o -E "\#.{0,6}" | sed "s/#/xc:#/g" | sed ':a;N;$!ba;s/\n/ /g')
convert -size 60X60 $VAR +append ${1::-4}palette.png
and it produces a "palette.png" image. But I do not know what to expect from ${1::-4} and
there is no sign of that in the output filename.
But when I insert the variables $1 and $2 in a bash script, it fails also.
Code: Select all
#!/bin/bash
VAR=$(convert $1 -colors $2 -depth 8 -format "%c" histogram:info: | sort -r -k 1 | head -n 16 | grep -o -E "\#.{0,6}" | sed "s/#/xc:#/g" | sed ':a;N;$!ba;s/\n/ /g')
convert -size 60X60 $VAR +append ${1::-4}palette.png
test.sh: line 3: -4: substring expression < 0
I think it does not like your ${1::-4}
But I am not that expert enough to tell you why. I don't understand ${1::-4}.
The script works fine if I remove ${1::-4}.
Perhaps it is confusing the ${1::-4} with your shell $1 and $2 arguments and not expecting -4
P.S. If you do not want your image to produce dithered colors, then add +dither before -colors X