Computer Hope

Software => BSD, Linux, and Unix => Topic started by: andy on October 25, 2021, 08:15:20 AM

Title: Linux script is not working complete
Post by: andy on October 25, 2021, 08:15:20 AM
hey everyone,

I am a beginner in linux, etc. now i need a script as task for school and it is not working good, the last echo's don't work like i would. Can someone help me?

#!/bin/bash
clear
read -p 'Geef een zin op en ik tel de karakters, laat het omgekeerd zien en geef nog eens de eerste en laatste 5 karakters:' zin
echo ....................................... .............
str=$zin
lengte=${#str}
echo "Het aantal karakters van de zin: '$str' is $lengte"
var=$zin
copy=${var}
len=${#copy}
for((i=$len-1;i>=0;i--)); do rev="$rev${copy:$i:1}"; done
echo "Omgedraaid krijg je: $rev"


echo "de eerste 5 karakters zijn: $zin" | cut -c1-5


echo "de laatste 5 karakters zijn: $zin" | rev | cut -c1-5 | rev

this last 2 lines should give the sentense "the first five caracters are ... and than the answer
same with the second one, but with the last 5 caracters.
can somone help?

thanks in advance
andy