Re: multiple spaces in bash strings.

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

 



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@xxxxxxxxxxxxxxxxxxxxxxx> 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@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



-- 
Jerry James
http://www.jamezone.org/
-- 
_______________________________________________
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