Search code examples
bashunixwebspherekshibmhttpserver

How to handle space in value - Unix KSH script


Any help on this will be great. Here is a script which uses a variable rootCerLabel in Props.txt to add a certificate in a keystore via a command but the command fails because variable rootCerLabel's value has spaces in it, I am not sure how to handle space in a value. I have tried escaping it will back slashes as well, but no luck.

Props.txt
rootCer="/services/EGcompanyInternalCA/ABC_EGcompany_G2_Root_CA.cer"
rootCerLabel=" 'ABC EGcompany G2 Root CA' "
IHS_HOME="/usr/IhsInstalldir"

AddRootCA.sh

#!/usr/bin/ksh

. Props.txt
addRootCertificates(){
echo "Adding root and intermidiate in keystore"
$IHS_HOME/bin/gskcapicmd -cert -add -file $rootCer -db $IHS_HOME/InteralSSL/key.kdb -stashed -label $rootCerLabel
echo "Added root and intermidiate in keystore."
}

sh -x AddRootCA.sh

+ rootCer=/services/EGcompanyInternalCA/ABC_EGcompany_G2_Root_CA.cer
+ rootCerLabel='ABC EGcompany Root CA'
+ IHS_HOME=/usr/IhsInstalldir
+ echo "Adding root and intermidiate in keystore"
+ /usr/IhsInstalldir/bin/gskcapicmd -cert -add -file /services/EGcompanyInternalCA/ABC_EGcompany_G2_Root_CA.cer -db /usr/IhsInstalldir/InteralSSL/key.kdb -stashed -label 'ABC EGcompany Root CA'

CTGSK3020W Invalid object: EGcompany

-Command usage- Object Action Description ------ ------ ----------- -locale Set the display lang


Solution

  • It matters where you do the quoting. You can put as many quotes in Props.txt as you want, if you incorrectly quote in AddRootCA.sh, you will not get the required result.

    Props.txt:

    rootCer="/services/EGcompanyInternalCA/ABC_EGcompany_G2_Root_CA.cer"
    rootCerLabel='ABC EGcompany G2 Root CA'
    IHS_HOME="/usr/IhsInstalldir"
    

    AddRootCA.sh:

    #!/usr/bin/ksh
    
    . Props.txt
    addRootCertificates(){
        echo "Adding root and intermediate in key-store"
        $IHS_HOME/bin/gskcapicmd -cert -add -file "$rootCer" -db "$IHS_HOME/InteralSSL/key.kdb" -stashed -label "$rootCerLabel"
        echo "Added root and intermediate in key-store."
    }