Find the answer to your Linux question:
Results 1 to 2 of 2
Do I have any errors on the following code? 1) #!/bin/ksh Echo “Type number 1” Read numbers If [ $numbers = 1 ]; Then Echo “the value was 1” Else ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2012
    Posts
    1

    Unix errors


    Do I have any errors on the following code?

    1) #!/bin/ksh
    Echo “Type number 1”
    Read numbers
    If [ $numbers = 1 ];
    Then
    Echo “the value was 1”
    Else
    echo “the value was not 1”
    fi

    2) Task 4 no.2
    #!/bin/ksh
    Echo enter 3 numbers
    Read n1
    Read n2
    Read n3
    ((total = n1 + n2 + n3))
    Echo $total
    (( division = total / 3 ))
    Echo your average is $division

    3)Task 4 no.3
    #! /bin/ksh
    echo "Please enter the amount of variable you would like” ;
    total=0
    read count
    set $count
    n=0
    while [[ $n -lt $count ]]
    do ((n=$n+1))
    read variable
    set $variable
    total=$(($total+$variable))
    echo "your number is $n"
    echo "your total is $total"
    done
    average=$(($total/$n))
    clear
    echo "The average is $average"

    4)Task 4 .4
    #! /bin/ksh
    echo "enter the file you wish to display"
    read filename
    set $filename
    if test -f $filename
    then
    less $filename
    $( gedit $filename )
    less $filename
    echo "here is your new edited file"
    less $filename
    else
    echo "your file does not exist"
    fi

    Task 4.5) #!/bin/ksh
    stop=0
    #test int1 equals int2
    while test $stop = 0
    do
    echo
    echo
    echo Main Menu
    echo
    echo 1 : edit the poem
    echo 2 : show more poem content
    echo 3 : show less poem content
    echo 4 : word count
    echo 5 : sort the poem with more
    echo 6 : sort the poem with cat
    echo 7 : exit poem
    echo
    echo please choose number
    read reply
    case $reply in
    "1") $(gedit poem.txt) ;;
    "2") more poem.txt ;;
    "3") less poem.txt ;;
    "4") wc poem.txt ;;
    "5") $(sort poem.txt > sortedpoem.txt) more sortedpoem.txt ;;
    "6") $(sort poem.txt > sortedpoem.txt) cat sortedpoem.txt ;;
    "7") stop=1 ;;
    * ) echo input invalid ;;
    esac
    done

  2. #2
    Linux Newbie
    Join Date
    Aug 2006
    Posts
    122
    -Why do you use KSH instead of Bash ? Old Solaris course ?
    -why don't you try by yourself ?
    I don't know KSH, but in 4.4, I would write :
    Code:
    if [ -f $filename]; then
    less $filename
    fi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •