Unix/Linux Go Back    


Solaris The Solaris Operating System, usually known simply as Solaris, is a Unix-based operating system introduced by Sun Microsystems. The Solaris OS is now owned by Oracle.

Substitution not working in ksh

Solaris


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-11-2007   -   Original Discussion by arsheshadri
arsheshadri's Unix or Linux Image
arsheshadri arsheshadri is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 27 June 2008, 8:24 AM EDT
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #2  
Old Unix and Linux 04-11-2007   -   Original Discussion by arsheshadri
reborg's Unix or Linux Image
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 14 Times in 12 Posts
That syntax is not valid in ksh88, which is the version you have since you are running on solaris.
Sponsored Links
    #3  
Old Unix and Linux 04-12-2007   -   Original Discussion by arsheshadri
pressy's Unix or Linux Image
pressy pressy is offline Forum Advisor  
solaris cultist
 
Join Date: Aug 2003
Last Activity: 4 October 2017, 11:02 AM EDT
Location: Vienna / Austria (Europe) [EARTH]
Posts: 739
Thanks: 1
Thanked 2 Times in 2 Posts
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 Unix and Linux 04-13-2007   -   Original Discussion by arsheshadri
Ygor's Unix or Linux Image
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 15 May 2015, 11:55 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 115 Times in 100 Posts
This syntax should work for both ksh and bash...
Code:
logname=${fname%dmp}log

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script is not working from cron while working manually anuragpgtgerman Shell Programming and Scripting 3 01-23-2012 02:54 PM
Difference between "Command substitution" and "Process substitution" royalibrahim Shell Programming and Scripting 3 12-15-2008 11:20 AM
Formatting Substitution Command Not Working in vi ERPKEN UNIX for Advanced & Expert Users 11 05-06-2007 10:36 PM
Substitution not working in ksh arsheshadri AIX 2 04-12-2007 08:30 AM
Var substitution in awk - not working as expected videsh77 Shell Programming and Scripting 3 01-13-2006 01:57 PM



All times are GMT -4. The time now is 10:24 PM.