Re: multiple spaces in bash strings. [SOLVED]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux