May 5, 2005 #1 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
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 Feb 5, 2004 1,231 EU Try Code: VAR=$(expr $VAR : "\(.*\).") Columb Healy Upvote 0 Downvote
May 5, 2005 #3 olded Programmer Oct 27, 1998 1,065 US #!/bin/ksh VAR=45: VAR=$(echo "$VAR"|sed 's/:$//g') echo $VAR Upvote 0 Downvote
May 5, 2005 2 #5 SamBones Programmer Aug 8, 2002 3,186 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 Jun 1, 2004 90 GB Thanks for all your help! Managed to finished my little script on time because of it. Upvote 0 Downvote