i don't understand this error that is always giving me, can you pls help me?
I am doing a homework and is really important and I am trying to figure out how to solve it since this early morning
param0="KcgMy4kfBovoomVUcvtkxXqh1xosedAq";
param1="r2UmsEnodjLin2zT94M7eAX76vpB7gTe";
param2=97;
output="";
f=0;
for (( i=0, j=0; i<${#param0}, j<${#param1}; i++, j++ ));
do c0=${param0:$i:1};
c1=${param1:$j:1};
renum="^[0-9]+$";
if [[ $c0 =~ $renum && $c1=~ $renum ]];
then param2=$((param2 - i - (c0 * c1)));
if (( param2 < 1 ));
then param2=$((-1 * param2));
f=$((!f));
fi;
output+=${param2};
else reupper="^[A-Z]+$";
if [[ $f -eq 1 && $c0 =~ $reupper ]];
then output+=${c0};
else output+=${c1}${c0};
fi;
fi;
if [[ $c0 =~ $realpha && $c1 =~ $realpha ]];
then reverse="";
for ((k = ${#output} - 1; k >= 0; k--));
do reverse=${reverse}${output:$k:1};
done;
output=$reverse;
fi;
done;
echo ${output:0:32};
Fixed missing space at the second Regex.
Don't forget to check your script with https://shellcheck.net/ or use a text editor with this as a plug-in.
Fixed your script:
#!/usr/bin/env bash
param0="KcgMy4kfBovoomVUcvtkxXqh1xosedAq"
param1="r2UmsEnodjLin2zT94M7eAX76vpB7gTe"
param2=97
output=""
f=0
for ((i = 0, j = 0; i < ${#param0}, j < ${#param1}; i++, j++)); do
c0=${param0:i:1}
c1=${param1:j:1}
renum="^[[:digit:]]+$"
if [[ $c0 =~ $renum && $c1 =~ $renum ]]; then
param2=$((param2 - i - (c0 * c1)))
if ((param2 < 1)); then
param2=$((-1 * param2))
f=$((!f))
fi
output+=${param2}
else
reupper="^[[:upper:]]+$"
if [[ $f -eq 1 && $c0 =~ $reupper ]]; then
output+=${c0}
else
output+=${c1}${c0}
fi
fi
realpha="^[[:alpha:]]+$"
if [[ $c0 =~ $realpha ]] && [[ $c1 =~ $realpha ]]; then
reverse=""
for ((k = ${#output} - 1; k >= 0; k--)); do
reverse=${reverse}${output:k:1}
done
output=$reverse
fi
done
printf %s\\n ${output:0:32}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.