-1

I would like to use for loop to create files in shell. I have 3 files named sensor_1.nmf, sensor_2.nmf, sensor_3.nmf, and I want to use a software to create another 7 python files for each files above,i.e., Using sensor_1 creates 7 python files like r_sensor_1.py, r_sensor_2.py ... My code is below:

for j in 1 2 3
do
    for k in 1 2 3 4 5 6 7
        nacs2.2 -l nacs_mphs -m sensor_${j}.nmf -p r_sensor_${k}.py r_sensor_${j}_${k}
    done
done

But it can not work. Could somebody help me? Thanks.

0

You can use brace expansion as opposed to iterating through the for loops.

nacs2.2 -l nacs_mphs -m sensor_${1,2,3}.nmf -p \
r_sensor_${1,2,3,4,5,6,7}.py r_sensor_${1,2,3}_${1,2,3,4,5,6,7}
0

At your inner for-loop you are missing the "do".

for j in 1 2 3
do
  for k in 1 2 3 4 5 6 7
  do
     nacs2.2 -l nacs_mphs -m sensor_${j}.nmf -p r_sensor_${k}.py r_sensor_${j}_${k}
  done
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.