Skip to content
Advertisement

Execute a command on all the files within a directory

I am trying to write a bash script that could automate a programme on all the files present in a directory. The files that are in my directory are in the .nii or .nii.gz format.

The command that I have to write is

    run_first_all -i InputFile -o OutputFile

InputFile is the name of the file that has to be processed by the programme, and OutputFile would be the name given to the file after it has been processed by the programme. I tried writing it like this

    #!/bin/bash
    for file in /dir/*.nii
    do
    run_first_all -i "$file" -o "$file"
    done

But, I get this error message

Advertisement

Answer

Try something like:

while IFS=  read -r -d $''
do
  file=$REPLY
  echo "file: "$file""
  run_first_all -i "$file" -o "${file}.out"
done < <(find /dir/ -name "*.nii" -print0)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement