I am about to create a frame as a function, around my title, but when I call the function I always get a message, function not found. I can't find why it is not working.
The error I get:
banner.sh: 3: function: not found
+-+
banner.sh: 11: Syntax error: "}" unexpected
Code snippet:
function cover {
length=${#1}
echo -n '+'
for i in {0..$length-3}
do
echo -n '-'
done
echo '+'
}
At the end I would just call the function like that:
cover
echo "previously declared string variable"
/path/to/banner.sh
?sh banner.sh
?bash banner.sh
? something else?). – terdon Dec 05 '22 at 10:38{0..$length}
is ksh compatible – Gilles Quénot Dec 05 '22 at 10:44ksh
, you can't use{0..$length-3}
without it becoming a concatenation of the value of$length
and the string-3
. And, in any case, the OP seems to be usingbash
. – terdon Dec 05 '22 at 10:51bash
, and 2) you can't use a variable (or integer expression) as the end of a range used in a brace expansion inbash
. – Kusalananda Dec 05 '22 at 13:19