Bash loop string and add string to it Bash loop string and add string to it shell shell

Bash loop string and add string to it


Your bash syntax is not correct.

#!/bin/bashstring1=hellostring2=worldoutput=$string1" "$string2for i in {1..10} ; do  echo $output  output=$output" "$string2done

Edit: or, taking into account the comments below for the sake of beauty of code:

#!/bin/bashstring1="hello"string2="world"output="$string1 $string2"for ((i = 1; i <= 10; i++)) ; do  echo "$output"  output+=" $string2"done


you can do this by writing to a variable, appending to it in an inner loop and then echo it out:

string1="string1"string2="string2"for ((i=1;i<=10;i++)); do  output="$string1"  for ((j=1;j<=$i;j++)); do    output+=" $string2"  done  output+=  echo $outputdone