Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Bash Shell Online

# Test of STDIN input conversion

declare -a inputValues
function deleteEndLine {
   local size=${#1}
   let size-=1
   local final=${1:0:$size}
   echo "$final"
}

function readAllInputVariables {
   read endInput
   while [ "$endInput" != "ENDOFINPUT" ]
   do
      endInput="$(deleteEndLine $endInput)"
      inputValues+=($endInput)
      read endInput
   done
}

function baseSum {
   local basicSum=0
   if [$1 -eq 1];
   then
      basicSum=1
      echo "$basicSum"
   else
      local nextValue
      let nextValue=$1-1
      let basicSum=$1+"$(baseSum $nextValue)"
      echo "$basicSum"
   fi
}

readAllInputVariables
echo "ESTOY AQUIIIII"
finalSum="$(baseSum ${inputValues[0]})"
echo "$finalSum"

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.