I suppose the easiest way to explain my problem is to show you some code and then show you what the code outputs:
--------------------------------------------------
#!/bin/bash
echo "This line has spaces" > "/tmp/This Filename Has Spaces.txt"
export Foo=$(cat "/tmp/This Filename Has Spaces.txt")
VarName=Bar
export $VarName=$(cat "/tmp/This Filename Has Spaces.txt")
echo $Foo
echo $Bar
--------------------------------------------------
This is the output:
This line has spaces
This
How do I get the "Bar" variable to output the full string?
Thanks so much!
It might help if u were to explain what you were trying to accomplish and I might be able to help further. However, in the examples you outlined try adding the following lines at the beginning of the script :
CFS=$IFS
IFS=$(echo)
and then add the following at the end of the script to set the IFS (Internal Field Separator) back.
IFS=$CFS
Should look like this
-----------------------------
#!/bin/bash
CFS=$IFS
IFS=$(echo)
echo "This line has spaces" > "/tmp/This Filename Has Spaces.txt"
export Foo=$(cat "/tmp/This Filename Has Spaces.txt")
VarName=Bar
export $VarName=$(cat "/tmp/This Filename Has Spaces.txt")
echo $Foo
echo $Bar
IFS=$CFS
Output will look like this :
This line has spaces
This line has spaces
It would be a long story for me to explain what I'm doing, but what you said worked! Thank you!
From your post, I learned that IFS stands for "Internal Field Separator", but what about "CFS"?
Thanks again!
CFS is just a variable I created to hold the current internal field separator (hence CFS - - current field separator) before I set it to $echo. And then it's used to set the IFS back to it's original setting (IFS=$CFS).
Ah, that makes sense. You were a big help! Thanks!