#!/bin/bash
words_for_add="one two three four five six seven eight nine ten"
new_string="digits:"
for word_for_add in "$words_for_add"
do
new_string=$(echo "$new_string" | sed 's/$/ '"$word_for_add"'/')
done
echo "$new_string"
exit 0
# cycle_test
digits: one two three four five six seven eight nine ten
но:
#!/bin/bash
words_for_add=$(echo "one two three four five six seven eight nine ten" | tr ' ' '\n')
new_string="digits:"
echo "$words_for_add" | while read word_for_add
do
new_string=$(echo "$new_string" | sed 's/$/ '"$word_for_add"'/')
done
echo "$new_string"
exit 0
# cycle_test
digits:
Почему так?