(replying to several)
Thank-you everyone that replied.
This is the first bash script I've tried to write in about 8 years.
The '$' in front of the variable in the left side of the assignment was
definitely an error. Removing it eliminated an error message.
Thank-you, everyone. But that's not the real focus of this thread. The
real problem is how to do this:
string2=
string1
concatenated_to
more_than_one_space
concatenated_to
string2
(I wish bash had an explicit string concatenation operator!)
Why does this work:
onespace=" "
longstring=${startstring}${onespace}${onespace}${onespace}${longstring}
echo "longstring = \"$longstring\"."
but this not work:
longstring=${startstring} ${longstring}
echo "longstring = \"$longstring\"."
?!
I could not get Todd's suggestion to work. Could it be a difference
between doing it in the command line vs. doing it inside a bash shell
script? or the spaces being a part of one operand vs. being a separate
operand? or prepend vs. append?
Jerry's "IFS" suggestion works. I wonder what percent of this list's
members knew about "IFS" in bash before I launched this thread. I spent
some time in the web site that Jerry pointed me to. "IFS" is in there
33 times. But I did not see it defined; I don't really understand it.
If I go that route, it will be by "blind faith". Isn't there a clearer,
easier-to-understand way?
On 7/1/25 9:42 PM, home user via users 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