Hello I am building a bash script, I would like to use xargs to do a call of my_command in parallel, issue is that with the command below, the variable $input_file is not available.

command is looking like:


awk 'BEGIN{OFS=""} {print $1,":",$2,"-",$3}' data.txt| xargs -P 4 -I {} -n 1 sh -c 'my_command -r {} $input_file > file_per_parameter.txt'

How can I access the variable $input_file from inside of the command (with keeping {} available)

1 Answer 1


It seems that I found out the solution, I just need to export the variable so solution is: export input_file=my_file.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .