08-12-2010
Specifying a range within case/esac
Complete Unix beginner here. I basically have this script -
Quote:
time1=`date +%l:%M`
case `date +%H` in
"00") time2="in the early morning" ;;
"01") time2="in the early morning" ;;
"02") time2="in the early morning" ;;
"03") time2="in the early morning" ;;
"04") time2="in the early morning" ;;
"05") time2="in the morning" ;;
"06") time2="in the morning" ;;
"07") time2="in the morning" ;;
"08") time2="in the morning" ;;
"09") time2="in the morning" ;;
"10") time2="in the morning" ;;
"11") time2="in the morning" ;;
"12") time2="in the afternoon" ;;
"13") time2="in the afternoon" ;;
"14") time2="in the afternoon" ;;
"15") time2="in the afternoon" ;;
"16") time2="in the afternoon" ;;
"17") time2="in the evening" ;;
"18") time2="in the evening" ;;
"19") time2="in the evening" ;;
"20") time2="at night" ;;
"21") time2="at night" ;;
"22") time2="at night" ;;
"23") time2="at night" ;;
esac
echo "The time is$time1 $time2"
This seems to work fine. I want to try and shorten it by making it something like this -
Quote:
time1=`date +%l:%M`
case `date +%H` in
[00-04] ) time2="in the early morning" #and so on...
esac
This isn't working. I think it's probably to do with the zero padding that `date +%H` gives me, but if I use `date +%k`, I get a space at the start of single numbers, so that doesn't work either... Can anyone tell me where I'm going wrong?
Thanks in advance.
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
2. Shell Programming and Scripting
HELLO ALL,
URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE.
FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY
and the CITY column records will be: Newyork
washington
... (1 Reply)
Discussion started by: abhilash mn
1 Replies
3. UNIX for Dummies Questions & Answers
Wrote the following loop to but if I use exit, then I break entirely from my script, but instead I want to break from the case/esac and go to the next line in my script. I guess I need to know how to exit gracefully from a "while (true). Also, how can I allow the user to enter upper or lowercase... (4 Replies)
Discussion started by: tumblez
4 Replies
4. Shell Programming and Scripting
I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated.
e.g.
Pattern1
Bombay
Calcutta
Delhi
Pattern2
Pattern1
Patna
Madras
Gwalior
Delhi
Pattern2
Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies
5. UNIX for Dummies Questions & Answers
Hey guys,
I'm trying to setup a case statement that checks a value against 5 separate ranges of numbers.
Here are the things I've tried with no success.
case "$AGE" in
"<10") echo "You're in this decade.";;
"") echo "You're in this decade.";;
"") echo "You're in... (5 Replies)
Discussion started by: fufaso
5 Replies
6. Shell Programming and Scripting
Hi
I want to make string substitution ignoring case for search but respecting case for subtitute. Ex changing all occurences of "original" in a file to "substitute":
original becomes substitute
Origninal becomes Substitute
ORIGINAL becomes SUBSTITUTE
I know this a little special but it's not... (1 Reply)
Discussion started by: kmchen
1 Replies
7. Shell Programming and Scripting
Is there a command that can switch a character variable from UPPER case to lower case?
like
foreach AC ( ABC BCD PLL QIO)
set ac `COMMAND($AC)`
...
end
Thanks a lot! (3 Replies)
Discussion started by: rockytodd
3 Replies
8. Shell Programming and Scripting
Hello Unix Gurus :
It would be really appreciative if can find a solution for this .
I have records in a file .
I need to Capitalize the records based on condition .
For Example i tried the following Command
COMMAND -->
fgrep "2000YUYU" /export/home/oracle/TST/data.dat | tr '' ''... (12 Replies)
Discussion started by: tsbiju
12 Replies
9. Shell Programming and Scripting
hi Scripting experts, I am using case..esac in my script .. I have given 6 option..e.g. 1 2 3 4 5 and *, howerver my script works welll for 1st 4 options but for 5 it considers * and exists. Is there a maximum limit on number of options given for case ..esac? (1 Reply)
Discussion started by: sdgawande
1 Replies
LEARN ABOUT PLAN9
yesterday
YESTERDAY(1) General Commands Manual YESTERDAY(1)
NAME
yesterday - print file names from the dump
SYNOPSIS
yesterday [ -c ] [ -date ] files ...
DESCRIPTION
Yesterday prints the names of the files from the most recent dump. Since dumps are done early in the morning, yesterday's files are really
in today's dump. For example, if today is March 17, 1992,
yesterday /adm/users
prints
/n/dump/1992/0317/adm/users
In fact, the implementation is to select the most recent dump in the current year, so the dump selected may not be from today.
With option -c, yesterday copies the dump file to the current directory.
The date option selects other day's dumps, with a format of 2, 4, 6, or 8 digits of the form dd, mmdd, yymmdd, or yyyymmdd.
Yesterday does not guarantee that the string it prints represents an existing file.
EXAMPLES
Back up to yesterday's MIPS binary of vc:
cd /mips/bin
yesterday -c vc
Temporarily back up to March 1's MIPS C library to see if a program runs correctly when loaded with it:
bind `{yesterday -0301 /mips/lib/libc.a} /mips/lib/libc.a
rm v.out
mk
v.out
FILES
/n/dump
SOURCE
/rc/bin/yesterday
SEE ALSO
fs(4)
BUGS
It's hard to use this command without singing.
YESTERDAY(1)