Artificial intelligent assistant

why doesn’t my if structure work? I want to add .java to my string if it doesn't have it already. How can I make this work with an `if` structure? This is what I tried: 6 echo geef eens je naam van je java programma? 7 8 read naam 9 firstletter=${naam:0:1} 10 11 naamm="${naam^}" 12 echo $naamm 13 14 add=".java" 15 16 if [ ${naamm:(-5)} != ".java" ] 17 then 18 naamm=$naamm$add 19 echo $naamm 20 else 21 #nothing 22 fi

Several possibilities:


if ! [[ $naamm =~ \.java$ ]]


or


name="${name%.java}.java"


or


if [ "${name: -5}" = '.java' ]


**additional question**

Content can be written to a file like this:


echo "public class $naamm {
public main..." >file


For bigger contents this approach is easiert:


cat <<\EOT >file
public class $naamm {
public main...
EOT

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a0c144f3d416eb8bc8b1e3295bfa5e2e