I have a script that need to be run under the (mainly) 3 environment (AIX, Linux [Red hat], sun [nearly no more due to migration]) but always under ksh (not ksh93)
i try to assign value to variable that will work on the 3 environnement, especially resulting of operation like wc -l or sed/awk, ...
due to specification and shell interpretation i can not find a generic code for this. I can use if command to use a specific version of assignation code base on OS but the code need to be understand by each shell
sample of problem (and eval solution) with array declaration
if ${HostLinux} then eval 'typeset -a aModeTrace=( [0]=false [1]=false [2]=false [3]=false )' else eval 'set -A aModeTrace false false false false' fi now i have a string to sed and assign to a variable the aix code work with
ThisLine="have a \" and a ' or maybe a \\; and many more other char like any log file could have" cst_PrintfPipeOS=" " SampleSize=24 printf '%s%s' "${ThisLine}" "${cst_PrintfPipeOS}" | sed -e "s/^\(.\{${SampleSize}\}\).*/\1/" | read Result To be easy, i can use the 3 var HostLinux, HostSun and HostAix set to true/false depending running environement (only 1 is true as you could imagine)
1) how to deal with equivalent of | read in linux where the code does not hang on AIX/SUN (code like read Result <<< hang on AIX) 2) using a Result="some code" is dependant of " and ' content and variable surrounding quote
I try to avoid eval on every assignation line (there are more than 1500 lines, imagine the code and the comment and the fun to debug)
Solution used (thanks @Gilles)
use of the ="$( some code without escape specific) liek for a ='some code' (' for back quote)
Result1="`echo '\"'`" Result2="$(echo '"')" echo '+Grep' set | egrep "[R]esult" -> Result1=" Result2=" +Grep Result1='"' Result2='"' specific not recognize code still need to be "evaluate" via string