memecs
memecs

Reputation: 7564

GNU parallel: how to format replacement string?

I am trying to achieve the following and I want to do it on multiple processes using GNU parallel.

for i in $(seq 0 3); do
 var=$(printf "%.5d" $i)
 echo test_$var
done

 Output:
--------------------
test_00000
test_00001
test_00002

I tried this and it's not working:

parallel var=$(print "%.5d" {})\; echo test_$var ::: $(seq 0 3)

Upvotes: 5

Views: 1695

Answers (1)

that other guy
that other guy

Reputation: 123460

You're expanding the command substitution before you run parallel, which is why it fails.

You can avoid this with single quotes:

parallel 'var=$(printf "%.5d" {}); echo test_$var' ::: $(seq 0 3)

Upvotes: 6

Related Questions