Bash: Problem to prepend text to variable
The output of following code is not like it's intended ...
Code:
echo "Test prepending ..." Code:
Test appending ... Would be very grateful for any clues! Thanks in advance! |
This has several issues:
1. Misuse of quotes. You don't need to quote the items to loop through, but you *do* need to quote any expansion (echo "$appended" and echo "$prepended") 2. Useless use of echo. "$(echo "$words")" is equivalent to just "$words" 3. The prepended=("...") construct creates an *array* of one item and assigns it to the variable prepended. Probably not what you want to do. Please throw out whatever it is you're trying to use to learn and read this: http://mywiki.wooledge.org/BashGuide |
Sorry for confusing prepend with append. See edit in last post.
|
Thanks for your reply!
Actually, the stupid example is my own invention :) What would be a working way to prepend a string to the items in the for-loop? |
This works as intended:
Code:
for words in apple hour Removed useless echos and quotes as tuxdev suggested. |
All times are GMT -5. The time now is 09:02 PM. |