Substitution not working in ksh


 
Thread Tools Search this Thread
Operating Systems Solaris Substitution not working in ksh
# 1  
Old 04-11-2007
Substitution not working in ksh

Hi,

Following code is working in bash but not in ksh.
Can someone please send me an alternative?

#!/bin/ksh
fname="EOA.dmp"
echo $fname
logname=${fname/.dmp/.log}
echo $logname


I am getting below error in ksh
"testcmd[4]: logname=${fname/.dmp/.log}: 0403-011 The specified substitution is not valid for this command."

Thanks & Regards
Sheshadri
# 2  
Old 04-11-2007
That syntax is not valid in ksh88, which is the version you have since you are running on solaris.
# 3  
Old 04-12-2007
the default ksh on solaris is a posix ksh88 (/usr/bin/ksh), you can see the version in vi mode with "<esc> <ctl> v"

but there is another ksh on solaris, the ksh93 with X, Xt, Xm and CDE functions called dtksh (/usr/dt/bin/dtksh). here it works:

Code:
pressy@jumpy # /usr/bin/ksh -o vi
pressy@jumpy #
pressy@jumpy # Version M-11/16/88i
pressy@jumpy # fname="EOA.dmp"
pressy@jumpy # echo $fname
EOA.dmp
pressy@jumpy # logname=${fname/.dmp/.log}
/usr/bin/ksh: logname=${fname/.dmp/.log}: bad substitution
pressy@jumpy #
pressy@jumpy # /usr/dt/bin/dtksh -o vi
pressy@jumpy # Version M-12/28/93d
pressy@jumpy #
pressy@jumpy # fname="EOA.dmp"
pressy@jumpy # echo $fname
EOA.dmp
pressy@jumpy # logname=${fname/.dmp/.log}
pressy@jumpy # echo $logname
EOA.log
pressy@jumpy #

regards pressy
# 4  
Old 04-13-2007
This syntax should work for both ksh and bash...
Code:
logname=${fname%dmp}log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parameter substitution is not working with sed

I am trying add a prefix variable(string) to command output. sed parameter substitution is not working. - I have found some issues on my end of testing,, please delete this thread for now. (1 Reply)
Discussion started by: kchinnam
1 Replies

2. Shell Programming and Scripting

Simple Variable substitution in ksh not working

Hi Gurus, Not able to catch what's going wrong here. I just want to get output as "tree". server:/mk/app/nexapp $ echo $SHELL /usr/bin/ksh server:/mk/app/nexapp $ export db_name1="tree" server:/mk/app/nexapp $ export i=1 1st try: server:/mk/app/nexapp $ echo $(db_name$i) ksh: db_name1: ... (3 Replies)
Discussion started by: mukesh.lalwani
3 Replies

3. Shell Programming and Scripting

Using Sed to do a substitution inside ksh

I'm trying to do an ls from inside of a ksh script. I loop through the results one line at a time and attempt to do a substitution using sed to convert YYYYMMDD from the older files into the newer files. Basically sometimes the ETL load runs over midnight and half the files are off by one day... (3 Replies)
Discussion started by: Calbrenar
3 Replies

4. Shell Programming and Scripting

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 (2 Replies)
Discussion started by: LiorAmitai
2 Replies

5. Shell Programming and Scripting

bad substitution error in ksh

hi, i created a shell script having the following content: #! /usr/bin/ksh FROM="myemail@domain.com" MAILTO="someemail@domain" SUBJECT="TEST" BODY="/export/home/adshocker/body.txt" ATTACH="/export/home/adshocker/attach.prog" echo $ATTACH ATTACH_NAME="${ATTACH##*/}" echo $ATTACH_NAME... (5 Replies)
Discussion started by: adshocker
5 Replies

6. Shell Programming and Scripting

variable substitution in ksh

Hi I have a variable BIT1 which holds some value. Is there a way to retrieve the value of this variable indirectly via another variable, lets say SUBSET_BIT_NUM=1, so the call will look something like this: sundev1 $ echo ${BIT${SUBSET_BIT_NUM}} ksh: ${BIT${SUBSET_BIT_NUM}}: bad substitution ... (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Shell Programming and Scripting

Double Substitution variables in ksh

Hi I have a variable whose value is like this i=/test/test1/test2/myfile.cd.070505123457 i would like to have the value of myfile.cd stored into another variable my attempt is test=${i##*/} ;echo $test ##and i get myfile.cd.070505123457 since what i wnat is myfile.cd i try this... (19 Replies)
Discussion started by: xiamin
19 Replies

8. AIX

Substitution not working in ksh

Following code is working in bash but not in ksh. Can someone please send me an alternative? #!/bin/ksh fname="EOA.dmp" echo $fname logname=${fname/.dmp/.log} echo $logname I am getting below error in ksh "testcmd: logname=${fname/.dmp/.log}: 0403-011 The specified substitution is not... (2 Replies)
Discussion started by: arsheshadri
2 Replies

9. Shell Programming and Scripting

KSH variable substitution

Hi folks Please let me know if anyone knows how to handle this. My KSH script -> testscript.ksh cmd=$1 ENV="devl" echo $cmd This is how I call the script ./testscript.ksh 'ps -ef | grep br$ENV' How do I get this to print the below text i.e $ENV should be substituted with the value... (5 Replies)
Discussion started by: tipsy
5 Replies

10. Shell Programming and Scripting

ksh substitution

Hello, I thought it was possible to use several time a #! entry on a script but it doesn't seems to work. My need is to have a part of a ksh script without substitution so it would look like #!/bin/ksh -- first part --- #!/bin/ksh -f -- part without substitution -- #!/bin/ksh --... (2 Replies)
Discussion started by: solea
2 Replies
Login or Register to Ask a Question