Saturday, April 23, 2022

[SOLVED] nohup for loop output naming

Issue

I use for loop to use specific tool with the set of files:

nohup sh -c 'for i in ~/files/*txt; do ID=`echo ${i} | sed 's/^.*\///'`; ./tool $i &&
mv output ${ID}.out; done' &

This tool has specific naming for outputted files and I want to rename the output as it would be overwritten and it is simpler for me.
However this specific mv doesn't work with nohup - files are not renamed individually and get overwritten.

How can I solve this problem.


Solution

Why the complicated nohup dance, and not just

for i in ~/files/*.txt; do
    ./tool $i && mv output `basename $i`.out
done


Answered By - nneonneo
Answer Checked By - Mary Flores (WPSolving Volunteer)