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

In ksh93 that would work too, but not in ksh88. You can use this:

TMP=12345; TMP2=${TMP%${TMP#??}}
MID=${TMP2#?}
1 Like

I just found another way to implement is is ksh using awk:

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

result: 23