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

need simple script to split a variable 1

Status
Not open for further replies.

dans45

Technical User
Feb 13, 2003
43
US
Hello,
I'm working on a simple korn shell script to combine a couple of variables and insert a period '.' between the characters in one of the variables.
Example of what i want in my script:
SN=1234567
I want to create a variable valued as 1234.567
SN1=`${SN:0:4}`
which I thought would set SN1 to 1234
SN2=`${SN:4}`
which I thought would set SN1 to 567
but these do not work as I get"the specified substition is not valid for this command".

Thanks for your help. I'm tired of guessing at this.
 
You are not doing anything wrong. The commands, as you have them in your example, are correct. The problem is your shell. I get the same error whenever I try to do most types of parameter expansion with ksh.

If you have access to a linux box, try the above under a bash shell and you will see that it works as expected.

I have not found a fix for this under ksh - but then again I havent really looked either.

scott
 
Make sure you are using ksh93. I use dtksh (which uses ksh93) when using the ${var:X:y} syntax.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top