1

I am trying to write a bash script to do a batch processing of some fMRI data. My problem is that I am not able to get the filenames that match a specific pattern within the directory of interest.

My scripts looks like this

#!/bin/bash

inputpath="/Volumes/External_HD/Experiments/MRI_Data"
outputpath="/Volumes/External_HD/Experiments/MRI_Data_output"

anatomical_scans=$find `$inputpath` -name *mprage

# RUN BET
bet $anatomical_scans $outputpath

echo 'Finished!!!'

The only output that I get is the following error message

-name: command not found

I am definetely not familiar with shell scripting so I am sorry if the question may sound trivial. Any help will be much appreciated.

Antonio

EDIT:: SOLVED

Exploring the suggestions I found the correct way to make it running with no errors

anatomical_scans=$(find $input_path -name "*mprage*")

Thanks

2
  • You miss some ''.. Take a look at this: stackoverflow.com/questions/8509226/… Commented Dec 6, 2017 at 16:20
  • 3
    Learn to use shellcheck.net before you post your code here ;-) . When you use shellcheck, you need to include a proper "she-bang" line as the first line, usually #!/bin/bash . AND avoid the top 10 shell script beginner mistakes by reading stackoverflow.com/tags/bash/info multiple times. Good luck. Commented Dec 6, 2017 at 16:26

3 Answers 3

4

try changing the line

anatomical_scans=$find$inputpath-name *mprage

to

anatomical_scans=$(find "${inputpath}" -name "*mprage")
Sign up to request clarification or add additional context in comments.

Comments

1

You can do the following:

#!/bin/bash

inputpath="/Volumes/External_HD/Experiments/MRI_Data"
outputpath="/Volumes/External_HD/Experiments/MRI_Data_output"

function anatomical_scans {
    find $inputpath -name "*mprage"
}

# RUN BET
bet anatomical_scans $outputpath

echo "Finished!!!"

Comments

1

You can try as below, hope it can help.

#!/bin/bash

inputpath="/Volumes/External_HD/Experiments/MRI_Data"
outputpath="/Volumes/External_HD/Experiments/MRI_Data_output"

anatomical_scans=`find $inputpath -name '*mprage'`

# RUN BET
bet $anatomical_scans $outputpath

echo 'Finished!!!'

1 Comment

Although it works, the syntax var=$(command) is preferred since it solves quoting issues, and others as described here: mywiki.wooledge.org/BashFAQ/082

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.