Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Having troubles writing a vi script.

    I have to write a script that says Hello, [current user]. Today is [date]. The time is [time am/pm]. You have logged into a [term] terminal.

    My script looks like this:

    DOW=`date +%A`
    MOY= `date +%B`
    DOM= `date +%d`
    TOD= `date +%1:%M`
    AOP= `date +%P`

    echo "Hello, $LOGNAME. Today is $DOW, $MOY, $DOM. The time is $TOD $AOP.
    echo "You have logged into a $TERM terminal."

    The problem is that $TERM has 'linux' lowercase and my boss wants it to read as 'Linux', so I tried this:

    for COL in 1
    UPPER=`echo "$INPUT" | cut -c $COL | tr '[a-z]' '[A-Z]'`
    echo "$INPUT" | sed 's/./'$UPPER'/'COL

    I changed the second line to read:
    echo "You have logged into a $INPUT=$TERM terminal."

    and it still just reads out as 'linux'. How can I fix it to say "You have logged into a Linux terminal." Without just hard coding it?

  2. #2
    You can do,

    uname$ubuntu:~$ s="$TERM"
    uname$ubuntu:~$ s="`echo ${s:0:1} | tr [:lower:] [:upper:]`${s:1}"
    And s should store Linux.
    The script isolates the first letter (or rather, a sub-string from 0 to 1) of the string, passes it to tr and capitalises it; then it concatenates the capital letter with the rest of the string (or rather, a sub-string from 1 on).

Posting Permissions

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