Re: convert script to ksh93 (version 93) (417 Views)
Reply
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 1 of 6 (481 Views)
Accepted Solution

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

Honored Contributor
Steven Schweda
Posts: 9,090
Registered: ‎02-23-2005
Message 2 of 6 (468 Views)

Re: convert script to ksh93 (version 93 )

Acclaimed Contributor
Dennis Handly
Posts: 25,089
Registered: ‎03-06-2006
Message 3 of 6 (457 Views)

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
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 4 of 6 (432 Views)

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
Dennis Handly
Posts: 25,089
Registered: ‎03-06-2006
Message 5 of 6 (417 Views)

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
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 6 of 6 (397 Views)

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

 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.