Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first 3 letters of a VAR in ksh? 2

Status
Not open for further replies.

jouell

MIS
Nov 19, 2002
304
US
Hi,

Does ksh allow me to return "Sep" if my variable is September (I am not using the date command in the script) ?

I.E.

month=September
echo $month{1-3} or something?

Didnt find it in man for ksh.

tks!
-john
 
Something like this ?
typeset -L3 y=$month;echo $y

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
#!/bin/ksh
echo "${month%${month#???}}"

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Yet another way:
expr substr $month 1 3

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the fast responses!!! That is the ticket!
-john
 
Using ksh93:

# month=September
# print $month
September
# print ${month:0:3}
Sep
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top