bad substitution error in ksh | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

bad substitution error in ksh

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-03-2011
LiorAmitai LiorAmitai is offline
Registered User
 
Join Date: Jan 2011
Last Activity: 10 January 2012, 3:42 AM EST
Posts: 43
Thanks: 16
Thanked 2 Times in 1 Post
Tools bad substitution error in ksh

Hello,

In bash I can use the following:
TMP=12345
MID=${TMP:1:1}

the expected result is: 2

but when using KSH I'm getting a ''bad substitution" error.

What is the correct syntaxin ksh?

Thanks
Sponsored Links
    #2  
Old 01-03-2011
Scrutinizer's Avatar
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 31 October 2014, 3:05 PM EDT
Location: Amsterdam
Posts: 9,562
Thanks: 286
Thanked 2,430 Times in 2,177 Posts
In ksh93 that would work too, but not in ksh88. You can use this:

Code:
TMP=12345; TMP2=${TMP%${TMP#??}}
MID=${TMP2#?}

The Following User Says Thank You to Scrutinizer For This Useful Post:
LiorAmitai (01-03-2011)
Sponsored Links
    #3  
Old 01-06-2011
LiorAmitai LiorAmitai is offline
Registered User
 
Join Date: Jan 2011
Last Activity: 10 January 2012, 3:42 AM EST
Posts: 43
Thanks: 16
Thanked 2 Times in 1 Post
I just found another way to implement is is ksh using awk:

tmp=123456
echo $tmp | awk '{print substr($tmp,2,2)}'


result: 23
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
vi substitution drareeg Shell Programming and Scripting 2 11-07-2010 07:07 PM
bad substitution Error while renaming Extension paragkhanore Shell Programming and Scripting 6 06-09-2010 12:45 PM
sed substitution tom.lee Shell Programming and Scripting 2 10-02-2009 09:37 AM
Difference between "Command substitution" and "Process substitution" royalibrahim Shell Programming and Scripting 3 12-15-2008 10:20 AM
Variable substitution error cosec Shell Programming and Scripting 4 12-12-2007 03:40 AM



All times are GMT -4. The time now is 03:16 PM.