Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Linux script is not working complete  (Read 77741 times)

0 Members and 1 Guest are viewing this topic.

andy

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 10
    Linux script is not working complete
    « 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