LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Errors executing shell script: "command not found" and "no such file or directory" (http://www.linuxquestions.org/questions/linux-newbie-8/errors-executing-shell-script-command-not-found-and-no-such-file-or-directory-856270/)

eko000 01-14-2011 06:41 AM

Errors executing shell script: "command not found" and "no such file or directory"
 
Dear linux users,

I am new to shell scripting and any advice you have would be much appreciated.

A colleague gave me a shell script ("dti_motion") which needs to be run from the directory containing all the files it works on. I want to run the same script for several different directories. But I don't want to have to cd into each directory, run the script, wait for it to finish, and then cd to the next directory (there are 52 to do altogether).

So I wanted to write a very simple script that will cd to each directory and perform the script there, before going on to the next one.

My colleague's script ("dti_motion") is stored in my home/bin/ and is executable. My home/bin/ is in my path, as verified by echo $path. When run from a directory containing the necessary information, the dti_motion script works perfectly well.

I wrote an extremely inelegant script called "dti_motion_do_all" which is also stored in my home/bin/ and executable:

#!/bin/sh

#Get motion information for each subject, using Mark's script, called dti_motion

cd /imaging/cr01/PD_DTI/C_10/12x5
.dti_motion C10_12x5ec.ecclog (<--This .ecclog file is required by the dti_motion script as $1 and is stored in C_10/12x5)

cd /imaging/cr01/PD_DTI/C_10/30x2
.dti_motion C10_30x2ec.ecclog

#End of dti_motion_do_all script

When I type dti_motion_do_all at the command line to run it, this produces the error
/home/cr01/bin/dti_motion_do_all.sh: line 6: .dti_motion: command not found
/home/cr01/bin/dti_motion_do_all.sh: line 9: .dti_motion: command not found

I tried changing the dti_motion_do_all script to

#!/bin/sh

#Get motion information for each subject, using Mark's script, called dti_motion

cd /imaging/cr01/PD_DTI/C_10/12x5
. ./home/cr01/bin/dti_motion C10_12x5ec.ecclog

cd /imaging/cr01/PD_DTI/C_10/30x2
. ./home/cr01/bin/dti_motion C10_30x2ec.ecclog

#End of dti_motion_do_all script

And this then produces the following error when I run it:
/home/cr01/bin/dti_motion_do_all.sh: line 6: ./home/cr01/bin/dti_motion: No such file or directory
/home/cr01/bin/dti_motion_do_all.sh: line 9: ./home/cr01/bin/dti_motion: No such file or directory

I know there will be more elegant ways to write this script with loops, rather than simply using cd, but for the moment, I just want this to run, until I have learnt to use loops properly.

Does anyone have any suggestions for how to correct either of those "command not found" or "no such file or directory" errors, given that both the original dti_motion and my dti_motion_do_all script are in my /home/bin/ (which is on my path) and both scripts are executable?

Many thanks

eko000 01-14-2011 08:54 AM

SOLVED - A colleague advised me, the dti_motion_do_all script should read:

#!/bin/sh

#Get motion information for each subject in each of the two datasets, using Mark's script, called dti_motion

cd /imaging/cr01/PD_DTI/C_10/12x5
/home/cr01/bin/dti_motion C10_12x5ec.ecclog

cd /imaging/cr01/PD_DTI/C_10/30x2
/home/cr01/bin/dti_motion C10_30x2ec.ecclog

#End of script

I just needed to explicitly tell the shell where to find the dti_motion script. This now works :)

Also, in case any other linux newbies find it useful, a looped version would look like this:

#!/bin/sh

#Get motion information for each subject in each of the two datasets, using Mark's script, called dti_motion

for i in {11,12} <--numbers of your directories
do

for j in {12x5,30x2} <--numbers of your directories
do

cd /imaging/cr01/PD_DTI/C_${i}/${j}
/home/cr01/bin/dti_motion C${i}_${j}ec.ecclog


done

done

#End of script


All times are GMT -5. The time now is 08:28 PM.