user2867054
user2867054

Reputation: 59

bash script command not found - command correctly implemented

I wrote a bash script and i got these message:

/home/myname/documents/myscripts/run_tearingmode.sh: line 44: mpirun2: command not found:

Here the relevant part of the script

if [[ "$run_jobs" == "y" ]]
 then
 printf "The jobs run one after the other. Have fun with the analysis. \n "
 for ((i=1;i<=$number_subfolders;i++))
  do
  sub_folder=${main_folder}_$i
  cd
  cd gkw/run/${main_folder}/$sub_folder #change into certain subfold
  pwd
  mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x  #run on all 8 frames #line 44 Here is the problem 
  cd
 done
fi

My problem is, that when i type in the line as just a command in the certain folder, the programm runs correctly. This shows to me that i implemented it correctly. With pwd i also know that i am in the right folder. I didn't found out where i made the mistake. Do i need a certain bracket or equivalent things in a script for running a program? I also deleted the blank in front of the command, but nothing changed. What is wrong/missing?

EDIT: The problem was, that you can't run an alias from bashrc in such a script. So i added:

mpirun2='/Path/to/mpirun'

to my script and changed the command in the script to:

"$mpirun2" -np 8 ./gkw_btppx-gnu-DP_3481.x  #run on all 8 frames

This works. Thanks a lot. (I unfortunately can't write this answer myself as a starter :) )

Upvotes: 3

Views: 4209

Answers (2)

zzeroo
zzeroo

Reputation: 5636

I think if you add a shebang on top of your script

#/usr/bin/env bash

and the full path to your executable (this command shows it which mpirun2) this should work.

Upvotes: 1

LMC
LMC

Reputation: 12672

If mpirun2 is not on the user's PATH ('which -a' will return nothing). You must invoke it using full path to it:

/full/path/to/mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x

Upvotes: 1

Related Questions