On 7/3/25 4:29 PM, Samuel Sieb wrote:
On 7/3/25 3:11 PM, home user via users wrote:

snip

The things on the right are considered parameters and extra spaces are removed.  You need to quote it as mentioned by others.

longstring="${startstring}     ${longstring}"

That will keep all the spaces in between.

I looked back through the other posts. What you said is in their examples. But if they highlighted it in their comments, I missed it.

Yep, that works.  Thank-you.

The real script is over 250 lines so far. I'm still working on it. It was working up until the end, which was the subject of this thread. Here's the real code fragment:

# 220 lines of code above here constructs string variables
# line1, line2, line3, begchars, and endchars.
line1="${begchars}${line1}"
line2="${begchars}   ${line2}"
line3="${begchars}   ${line3}"
echo "before if, endchars = \"${endchars}\"."
if ! [ -z $endchars ]; then
   echo "adding closing tags."
   line1="${line1}${endchars}"
   line2="${line2}   ${endchars}"
   line3="${line3}   ${endchars}"
fi
echo "line1=\"${line1}\"."
echo "line2=\"${line2}\"."
echo "line3=\"${line3}\"."
# code that will go below here will use string variables
# line1, line2, line3, begchars, and endchars.

The "echo" statements are so I can track progress and for debugging. They will be commented out or removed after the script is done and tested.

I did try the "shellcheck" that Jeffrey suggested. It does flag the '$' at the beginning of the variable on the left side of assignments. It did not help with the disappearing spaces. But I can see that it would be a good help in general.

Thank-you Samuel and everyone else that posted. I've tagged this thread SOLVED.

--
_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Do not reply to spam, report it: 
https://pagure.io/fedora-infrastructure/new_issue

Reply via email to