BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

convert script to ksh93 (version 93 )

SOLVED
Go to Solution
Highlighted
Valued Contributor

convert script to ksh93 (version 93 )

hello,

 

i want to convert a script to ksh93 ( korn shell version 93 ) .

 

Ksh93: https://h20392.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=Ksh93

 

i want to replace following warning(s) like :

 

warning: line 1: `...` obsolete, use $(...)


following options i find in scripts, but some option's aren't possible to handle (for me)
like "var6" variante 6  in attachment. also "var4" is not ok. 

 

has anybody an idea ?

here are some options, what can be listed in a script KSH88

1. replace :  =`
    by          :  =$(

2. replace :  `$
    by          :  )

3. replace :  `character
    by           :  $(

4. replace :   character`
   by             : character )

5. replace :  ?`
    by          :  ? )

6. replace :  "`
     by         :  " )

7. replace :  }`
     by        :  } )

 

here is my "sed" converter :

file="demo.sh"

sed -e "s|=\`|=$\(|g" \
    -e "s|\`$|\)|g" \
    -e "s|\`\([a-z]\)|\$( \1|g" \
    -e "s|\([a-z\?\"\?]\)\`|\1 \)|g" ${file}  > ${file}.ksh93



ksh -n ${file}.ksh93

 

testing : sed of attachment and test syntax of new file with version 93 : ksh -n

 

kind regards

5 REPLIES
Honored Contributor

Re: convert script to ksh93 (version 93 )

 
Acclaimed Contributor

Re: convert script to ksh93 (version 93)

[ Edited ]

>warning: line 1: `...` obsolete, use $(...)

 

You should have done this as soon as you abandoned the Bourne and scummy C shell decades ago.

I started doing that as soon as I read "archaic" under Command Substitution.

(I  typically did it manually.)

 

sed -e "s|=\`|=$\(|g" \
    -e "s|\`$|\)|g" \
    -e "s|\`\([a-z]\)|\$( \1|g" \
    -e "s|\([a-z\?\"\?]\)\`|\1 \)|g" ${file}  > ${file}.ksh93

 

You can do this a little easier without all that quoting if you put it in single quotes:

sed -e 's|=`|=$(|g'   -e 's|`$|)|g'  -e 's|`\([a-z]\)|$( \1|g'  -e 's|\([a-z?"]\)`|\1 )|g'

 

(You don't need to quote the "?", nor have two of them.)

Valued Contributor

Re: convert script to ksh93 (version 93)

hello,

 

thx to your answers.

 

@ Steven

 

   

sed -e 's/`\([^`]*\)`/$(\1)/g'

 

this handle 90 % of my script(s).

 

That won't help if the two "`" characters are on different lines, as in:

     if [ `echo "var6" |grep "var6"  > /dev/null 2> /dev/null; \
            echo $?` -eq 0 ]

 

with the other "sed" options i can handle it ?  like :

 

sed -e 's/`\([^`]*\)`/$(\1)/g' -e 's|\([?]\)`|\1)|g'  -e 's| `\([a-z]\)| $(\1|g' -e 's|=`|=$(|g' -e 's|`$|)|g'

 

@ Dennis

 

in some scripts are statements  ( here it is a example of a "case" statement  ) like

var7=` echo "a b c" | \
       awk ' { print $1 } '`  ;;

 

 

so i want to "devaluate" the of sed

sed -e 's|\([?']\)`|\1)|g' demo_ksh88.sh

 

like :


sed -e 's|\([?\']\)`|\1)|g' demo_ksh88.sh

 

>

 

but i can't  devaluate in a class

 

regards

Acclaimed Contributor

Re: convert script to ksh93 (version 93)

[ Edited ]

>I want to "devaluate" the ' of sed

 

(This is called quoting in a shell.)

>sed -e 's|\([?']\)`|\1)|g' demo_ksh88.sh

You can stutter quotes: 'don'\''t'  (that's two single quotes, not double quote.
sed -e 's|\([?'\'']\)`|\1)|g' demo_ksh88.sh

Valued Contributor

Re: convert script to ksh93 (version 93)

@ Dennis : Thank you for your correction, now it works.

 

@ Dennis , Steven : With your input's i have a final solution :

 

sed -e 's/`\([^`]*\)`/$(\1)/g' -e 's|\([?'\''"]\)`|\1)|g' -e 's| `\([a-z]\)| $(\1|g' -e 's|=`|=$(|g' -e 's|`$|)|g'

 

this handle 95 % of ksh 88 script(s). the rest you have to correct manually.

 

regards