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: 
Me too!

```
export FOO=$(seq 0 7 | xargs -I{} echo "uops_dispatched_port.port_{}|p{}" | paste -sd,)

```

* `seq` generates numbers from 0 to 7
* `xargs -I{}` outputs the number in the strange format requested.
* `paste -sd,` joins the lines with the comma.
Also you can mark it as the last one and remove precisely

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

```