Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-11-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 87
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:
INPUT=linux
for COL in 1
do
UPPER=`echo "$INPUT" | cut -c $COL | tr '[a-z]' '[A-Z]'`
echo "$INPUT" | sed 's/./'$UPPER'/'COL
done
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?
- 02-13-2011 #2Just Joined!
- Join Date
- Feb 2011
- Posts
- 12
You can do,
And s should store Linux.Code:uname$ubuntu:~$ s="$TERM" uname$ubuntu:~$ s="`echo ${s:0:1} | tr [:lower:] [:upper:]`${s:1}"
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).


Reply With Quote
