May 5, 2005 #1 Autosys Programmer Joined Jun 1, 2004 Messages 90 Location 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
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
May 5, 2005 #2 columb IS-IT--Management Joined Feb 5, 2004 Messages 1,231 Location EU Try Code: VAR=$(expr $VAR : "\(.*\).") Columb Healy Upvote 0 Downvote
May 5, 2005 #3 olded Programmer Joined Oct 27, 1998 Messages 1,065 Location US #!/bin/ksh VAR=45: VAR=$(echo "$VAR"|sed 's/:$//g') echo $VAR Upvote 0 Downvote
May 5, 2005 1 #4 kHz MIS Joined Dec 6, 2004 Messages 1,359 Location US # var=45: # print ${var%%\:*} Upvote 0 Downvote
May 5, 2005 2 #5 SamBones Programmer Joined Aug 8, 2002 Messages 3,186 Location US 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. Upvote 0 Downvote
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.
May 6, 2005 Thread starter #6 Autosys Programmer Joined Jun 1, 2004 Messages 90 Location GB Thanks for all your help! Managed to finished my little script on time because of it. Upvote 0 Downvote