hi guys i have a function in bash , for me is correct but i dontknow why continue to tell me
./BBSW.sh: 17: Syntax error: Bad for loop variable
anyone can confirm me if is ok or not?
urlencode() {
local string="$1"
local length="${#string}"
local result=""
# Verifica se la sintassi del ciclo for è supportata
if [ -z "$(bash -c 'for ((i=0; i<1; i++)); do echo "OK"; done' 2>/dev/null)" ]; then
echo "Errore: La sintassi del ciclo for non è supportata in questa shell."
return 1
fi
for ((i = 0; i < length; i++)); do
local c="${string:$i:1}"
case $c in
[-_.~a-zA-Z0-9]) result+="$c" ;;
*) result+="%$(printf '%02X' "'$c")" ;;
esac
done
echo "$result"
}
my version is
bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http:
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
i use linux mint 64 last version
What I have tried:
i try also in this mode but nothing
urlencode() {
local string="$1"
local length="${#string}"
local result=""
for (( i = 0; i < length; i++ )); do
local c="${string:$i:1}"
case $c in
[-_.~a-zA-Z0-9]) result+="$c" ;;
*) result+="%$(printf '%02X' "'$c")" ;;
esac
done
echo "$result"
}