Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below

# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'

Resource List : <br>
*************************** 1. row ***************************<br>
          ID: 11337<br>
AVAILABILITY: RED<br>
    PLATFORM: qe-z1-mm CCM-Hardware<br>
   SORT_NAME: HARDWARE<br>
 DESCRIPTION: <br>
*************************** 1. row ***************************<br>
          ID: 15761<br>
AVAILABILITY: N/A<br>
    PLATFORM: 216<br>
   SORT_NAME: BG<br>
 DESCRIPTION: <br>
*************************** 1. row ***************************<br>



now if i try to store this into a variable something like this happens

vk=$( sed -n "/CCM-HQE-ResourceHealthCheck:/,/---------/{/CCM-HQE-ResourceHealthCheck:/d;/---------/d;p;}" TACHCAutomation.OutputZ$zoneCounter | sed 's/$/<br>/'  )


echo $vk

Resource List : <br> @ htmlGEN.sh myOutput.html myScript.sh sample.sh some.html TACHCAutomation.OutputZ1 TACHCAutomation.OutputZ2 TACHCAutomation.OutputZ3 TACHCAutomation.OutputZ4 TACHCAutomationOutput.html TACHCAutomationtemp1.txt TACHCAutomationtemp2.txt test.output test.output.html test.output_orig threshold.conf txt2HTML.sh txt2HTML.sh_backup_mar28 txt2HTML.sh_backup2 txt2HTML.sh_backup3 txt2HTML.sh_backup4 txt2HTML.sh_orig vk 1. row ***************************<br>
.
.
.
.ect ect

thse are nothing but folder contents where these files are... any workaround available for this.. i need to store the output in variable itself and not file...

It is stored right, but when you echo an unquoted string, substitution happens.

It takes the *'s to mean 'expand filenames' and flattens all white space when you echo an unquoted string. Try this:

echo "$vk"
1 Like

thanks a lot Corona.. quotes solved the issue.. gosh i have so much to learn,.... :slight_smile: