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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop last character from variable 3

Status
Not open for further replies.

Autosys

Programmer
Jun 1, 2004
90
GB
Hi there -

How do I drop the last character from a variable value. Say I have $VAR=45: I want to stip off the :

Note that the $VAR could have 4 characters for the value.

Cheers in advance!
S
 
Try
Code:
VAR=$(expr $VAR : "\(.*\).")

Columb Healy
 
#!/bin/ksh

VAR=45:
VAR=$(echo "$VAR"|sed 's/:$//g')
echo $VAR
 
Using [tt]sed[/tt] here is overkill. I second kHz's solution. In the Korn shell, the following will delete ANY last character from a variable.
Code:
VAR=45:
VAR=${VAR%?}
Hope this helps.
 
Thanks for all your help! Managed to finished my little script on time because of it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top