1

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};

1 Answer 1

3

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}
Sign up to request clarification or add additional context in comments.

1 Comment

We can say [[ $c0 =~ $renum && $c1 =~ $renum ]] with no problem. The bash manpage describes Expressions may be combined using the following operators, listed in decreasing order of precedence: <snip> expression1 && expression2. The possible problem is the lack of a whitespace next to $c1 as you point out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.