Interactive bash script

2. Determine the number of characters in your name
3. Display “Your <lastname> has <number> of characters”
5. Identify the first digit (ie 2 for 25 or 1 for 18), if less than 10 use 0, if greater than 99 use 10
6. Mulitply the first digit by 5
7. If your are older than 25 then add 3 to first digit*5, if you are younger than 25 add 6 to first digit*5
10. If you are are older than 25 then subtract 6, if you are younger than 25 then subtract 12
11. Echo “Your age is <value>”

###################################################################################

THIS IS WHAT I WROTE BUT NOT WORKING. HELP NEEDED

####################################################################################

#!/bin/bash

clear

echo -n "Enter last name: "

echo \$lname

echo ""

echo "your wc -c \$lname has wc -c \$lname characters."

echo ""

echo -n "Enter age: "

echo \$age

first="\$age"; echo \$(s:0:1)

second="\$age"; echo \$(s:1:1)

if [ \$age -le 0 ]; then

echo "0"

else

if [\$age -gt 99 ]; then

echo "10"

fi

fi

echo ""

if [ \$age -gt 25 ]; then

y=(\$first+3)*5

else

if [\$age -le 25 ]; then

y=(\$first+6)*5

fi

fi

echo ""

y=y*2

echo ""

declare -i second

age=\$age+second

if [ \$age -gt 25 ]; then

age=\$age-6

else

if [ \$age -le 25 ]; then

age=\$age-12

fi

fi

answered Jul 12 by (4,840 points)
edited Jul 13 by xDELLx

#!/bin/bash
clear
echo -n "Enter last name: "
echo \$lname
echo ""
#Display “Your <lastname> has <number> of characters”
echo "your \$lname has `echo \$lname | wc -c ` characters." #execute command between ` ` & then substitue its output in the echo string
echo ""
echo -n "Enter age: "
echo \$age
first=\${age:0:1}
second=\${age:1:1}
if [ \$age -le 10 ]; then
echo "0"
#age=0
else
if [ \$age -gt 99 ]; then
echo "10"
#    age=10
fi
fi
echo ""
#Mulitply the first digit by 5
first=`echo \$first*5 | bc`
#If your are older than 25 then add 3 to first digit*5, if you are younger than 25 add 6 to first digit*5
if [ \$age -gt 25 ]; then
#y=(\$first+3)*5
first=`echo "\$first + 3 " | bc`

else
#if you are younger than 25 add 6 to first digit*5
#if [ \$age -le 25 ]; then # this if is redundant as the comparison was done above
#    y=(\$first+6)*5
first=`echo "\$first + 6" | bc`
#fi
fi
echo ""
#y=y*2
first=`echo "\$first * 2" | bc `
echo ""
#declare -i second
#second=11