5

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)
Ole Tange
  • 31,768
  • 5
  • 86
  • 104
memecs
  • 7,196
  • 7
  • 34
  • 49

1 Answers1

6

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)
that other guy
  • 116,971
  • 11
  • 170
  • 194
  • From version parallel-20140722 you can use perl expressions directly: parallel echo '{= $_=sprintf("%.5d",$_) =}' ::: {0..3} – Ole Tange Jul 21 '14 at 06:14