Try this: IFS='' longstring="${startstring} ${longstring}"
You can read about IFS in the bash manual: https://www.gnu.org/software/bash/manual/bash.html On Wed, Jul 2, 2025 at 11:36 AM home user via users <users@lists.fedoraproject.org> wrote: > > f42 workstation. > > I'm trying to prepend a string and multiple spaces to another string. I > can't get it to work. How do I do it? See 3 attempts below. I really > do want multiple spaces between the startstring and the longstring. > > ----- > > me@road-runner:~$ cat spaces1.bash > #!/bin/bash > > #============================================================================== > > echo Enter start string: > read startstring > echo startstring = \"${startstring}\". > echo > > longstring="This is a long test string" > echo longstring = \"${longstring}\". > > $longstring="${startstring} ${longstring}" > echo longstring = \"${longstring}\". > me@road-runner:~$ ./spaces1.bash > Enter start string: > 11 > startstring = "11". > > longstring = "This is a long test string". > ./spaces1.bash: line 13: This: command not found > longstring = "This is a long test string". > me@road-runner:~$ > > ------ > > me@road-runner:~$ cat spaces2.bash > #!/bin/bash > > #============================================================================== > > echo Enter start string: > read startstring > echo startstring = \"${startstring}\". > echo > > longstring="This is a long test string" > echo longstring = \"${longstring}\". > > spaces3=" " > $longstring="${startstring}${spaces3}${longstring}" > echo longstring = \"${longstring}\". > me@road-runner:~$ ./spaces2.bash > Enter start string: > 22 > startstring = "22". > > longstring = "This is a long test string". > ./spaces2.bash: line 14: This: command not found > longstring = "This is a long test string". > me@road-runner:~$ > > ------ > > me@road-runner:~$ cat spaces3.bash > #!/bin/bash > > #============================================================================== > > echo Enter start string: > read startstring > echo startstring = \"${startstring}\". > echo > > longstring="This is a long test string" > echo longstring = \"${longstring}\". > > $longstring=${startstring} ${longstring} > echo longstring = \"${longstring}\". > me@road-runner:~$ ./spaces3.bash > Enter start string: > 333 > startstring = "333". > > longstring = "This is a long test string". > ./spaces3.bash: line 13: This: command not found > longstring = "This is a long test string". > me@road-runner:~$ > > ------ > > > -- > _______________________________________________ > 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 -- Jerry James http://www.jamezone.org/ -- _______________________________________________ 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