bashshellgnu-parallel

How to Interpret a Shell Variable in a String Value from a CSV Column Using GNU Parallel?


I'm trying to use GNU Parallel to execute commands based on the values in a CSV file. My CSV file has multiple columns, and the value in the 5th column of each row is a string that looks like '${OUTDIR}/test'.

Here's an example of how my CSV looks:

col1,col2,col3,col4,'${OUTDIR}/test',col6

I want to use GNU Parallel to run mkdir -p on the value of the 5th column, interpreting ${OUTDIR} as an actual shell variable. For example, if OUTDIR=/tmp, then the command should run as mkdir -p /tmp/test.

I tried the following command, but it didn't interpret ${OUTDIR}:

parallel --colsep ',' 'mkdir -p {5}' :::: data.csv

produced:

mkdir -vp \'\$\{OUTDIR\}/test\'
mkdir: created directory ''\''${OUTDIR}'
mkdir: created directory ''\''${OUTDIR}/test'\'''

How can I get GNU Parallel to interpret ${OUTDIR} in the string value from the CSV? I've tried using eval mkdir -p {5} but that doesn't deal with the quoting as I'd hoped.


Solution

  • Use the uq() function as shown by Ole here:

    parallel --colsep ',' 'echo {=5 uq(); =}' :::: data.csv