Question: Currently I use the following command to export the environment variable `FOO`:

```
export FOO=$(for i in {0..7}; do echo -n "uops_dispatched_port.port_$i|p$i,"; done)

```

This results in the string:

```
uops_dispatched_port.port_0|p0,uops_dispatched_port.port_1|p1,uops_dispatched_port.port_2|p2,uops_dispatched_port.port_3|p3,uops_dispatched_port.port_4|p4,uops_dispatched_port.port_5|p5,uops_dispatched_port.port_6|p6,uops_dispatched_port.port_7|p7,

```

I'd like a similarly simple, DRY, command that results in the same string without the trailing comma.

Answer: 
Would you please try the following:

```
export FOO=$(a=(); for i in {0..7}; do a+=("uops_dispatched_port.port_$i|p$i"); done; IFS=,; echo "${a[*]}")

```

The assignment to `IFS` is limited within the subshell and does not affect the following statements.
Give this a try:

```
export foo=$(awk 'BEGIN{for(i=1;i<=7;i++)printf "%suops_dispatched_port.port_%d|p%d",(i>1?",":""),i,i}')

```