Q:

how to add symbol in a string on bash

In a bash script i'm using command: 
branch=git branch --contains 86cf181ec0df06656e57c7787866087592

output:
branch1 branch2 branch3

In next step i'm using command:
list_of_commits=$(git rev-list 86cf181ec0df06656e57c7787866087592 $branch --first-parent | tail -n 1)

but argument $branch must be written ^branch1 ^branch2 ^branch3 from $branch and full command:
list_of_commits=$(git rev-list 86cf181ec0df06656e57c7787866087592 ^branch1 ^branch2 ^branch3 --first-parent | tail -n 1)

How i can to add symbol ^ before every output words in argument $branch in my script?

A:

Just loop through the records and prepend the ^:
$ d="hello i am muzzy"
$ echo "$d" | awk '{for (i=1;i<=NF; i++) {$i="^"$i} print}'
^hello ^i ^am ^muzzy

Also with awk '{for (i=1;i<=NF; i++) $i="^"$i}1' <<< "$d" taking advantage of 1, that triggers the printing of the full record, and using here-strings.
or if you want to save it in a new var:
$ new_d=$(echo "$d" | awk '{for (i=1;i<=NF; i++) {$i="^"$i} print}')
$ echo "$new_d"
^hello ^i ^am ^muzzy

In your case,
branch=$(echo "$branch" | awk '{for (i=1;i<=NF; i++) {$i="^"$i} print}')

