how to run non-standard commands in bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to run non-standard commands in bash script?
# 1  
Old 08-02-2010
how to run non-standard commands in bash script?

Hello All. I suspect that this will be a clear noob question, but I haven't been able to figure it out using the usual methods, so I turn to you.

I've written a script to create input files for the quantum chemistry program NWCHEM. Generally you create an input file and then execute it by typing at the command line:
>> nwchem inputfile.nw
and hitting enter. I've written a script for a huge batch of jobs that will create the folders and sub-folders, write the correct input file to the sub-folders and then...

Well, then it has to execute the command "nwchem inputfile.nw", but "nwchem" isn't a standard command like "cd" or "mkdir" so it doesn't do anything. I've tried just echoing it to the line along with the inputfile.nw name, but then of course it doesn't actually RUN it. I'm guessing that this is a path issue, but I'm not sure who to a) find the folder that contains the nwchem command that I use when I just type it to the command line manually and b) how to specify that and run it from the .sh script.

Is there an easier way to do this? Something that just tells bash to treat a particular group of words as a command just like mkdir or cd?

Thanks for any help you can give me. The process of trying to get this done has almost taken longer than just doing it all by hand without a script.

cheers,
EMF
# 2  
Old 08-02-2010
Since you can type and run the command nwchem in shell, the path of it has already in the PATH environment variable.
That is, it can also run in scripts without specifying the absolute path.
So I think your problem is another case.
If you wanna find out the path of the command, type "which nwchem" in shell.
# 3  
Old 08-03-2010
Yes, the path comes back /opt/local/share/nwchem/nwchem. Does this tell anyone anything about why I can't just use it in the .sh script the same way I do other (more standard) commands?

Thanks again for any help.

---------- Post updated at 09:11 PM ---------- Previous update was at 09:01 PM ----------

If it helps, here is what I have in there now:

path=$PATH:/opt/local/share/nwchem/nwchem
nwchem $basis_name$func_name$spin_name".nw"

This gives the error:
./nw_chem_DIMERscript.sh: line 152: nwchem: command not found
# 4  
Old 08-03-2010
When you say "it doesn't do anything" do you mean that you are getting an error message like "not found or no such file/directory," or literally nothing is happening?

There is a possibility that the command is being executed, but it is quietly aborting. Assuming that nwchem is either a bash or Kshell script, consider adding the command
Code:
set -x

at the start of nwchem -- if nwchem is being invoked, this might give you a clue as to why it is not executing as you intended.
# 5  
Old 08-03-2010
Quote:
Originally Posted by agama
When you say "it doesn't do anything" do you mean that you are getting an error message like "not found or no such file/directory," or literally nothing is happening?

There is a possibility that the command is being executed, but it is quietly aborting. Assuming that nwchem is either a bash or Kshell script, consider adding the command
Code:
set -x

at the start of nwchem -- if nwchem is being invoked, this might give you a clue as to why it is not executing as you intended.
I create all of the directories and then write the input file in that directory under the name $basis_name$func_name$spin_name".nw", then try to run the program by outputting
>> nwchem $basis_name$func_name$spin_name.nw
in the same manner that I would in the shell by hand but it tells me that this is not a command.

I included the set -x as you said in the following way:
path=$PATH:/opt/local/share/nwchem/nwchem
set -x nwchem $basis_name$func_name$spin_name".nw"
and it output a list of the failed if/then statements (but not the ones that passed), one (but not all) of the directory changes, the exit command etc. It didn't tell me "command not found" as before.
# 6  
Old 08-03-2010
Quote:
Originally Posted by EinsteinMcfly
I included the set -x as you said in the following way:
path=$PATH:/opt/local/share/nwchem/nwchem
set -x nwchem $basis_name$func_name$spin_name".nw"
and it output a list of the failed if/then statements (but not the ones that passed), one (but not all) of the directory changes, the exit command etc. It didn't tell me "command not found" as before.
I meant that set -x should be added inside of nwchem near the top (after the #!line if you are using that, otherwise as the first command). Sorry for the confusion.

You probably didn't get an error message this time round because the nwchem command after the 'set -x' was absorbed by the set command and there was no attempt to execute it.

Since you've said that you've been getting a 'not found' message, it does appear that it is a PATH issue, however from what you've posted it looks like you have your PATH setup to include the directory where nwchem exists.
Im not sure what is going on.
# 7  
Old 08-03-2010
You can add path=$PATH:/opt/local/share/nwchem/nwchem in ~/.bash_profile
then you have two choice:
1 source ~/.bash_profile
so ,you can use your command now.

2 log out and then log in
then you can find it works

Last edited by skles; 08-03-2010 at 02:56 AM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Run automated bash commands from sh login shell

I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the... (5 Replies)
Discussion started by: randman1
5 Replies

2. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

3. IP Networking

How to run an script and its commands via proxy?

Hi, i used this tutorial which tells me to use following example command to proxify traffic from my linux export {http,https,ftp}_proxy=122.228.156.126:80 when i do this command from command line it works and then i curl http://site/ipcheck.php i see its proxified, which is what i want to... (5 Replies)
Discussion started by: postcd
5 Replies

4. Shell Programming and Scripting

Run commands in a script in different shells

Hi to all, i have the following problem... i want to run three commands in a script in different shells... the first command is running always and is needed for the second on to run properly... example # Procedure 1 xterm -e exec1 arg1 arg2 # Procedure 2 xterm -e exec2 arg1 arg2 #... (6 Replies)
Discussion started by: paladinaeon
6 Replies

5. Shell Programming and Scripting

[bash] run a shell who runs commands

Hi all. On X11 I'm on a shell ...shell_1 (/bin/bash). From here I want to open another shell window shell_2 who executes commands like "ls -l" or programs like ". /program"... so the "result" of commands shows in shell_2 window and not in shell_1. Is that possible ? (4 Replies)
Discussion started by: jerold
4 Replies

6. Shell Programming and Scripting

Logging ALL standard out of a bash script to a log file, but still show on screen

Is it possible to store all standard-out of a bash script and the binaries it calls in a log file AND still display the stdout on screen? I know this is possible to store ALL stdout/stderr of a script to a single log file like: exec 1>&${logFile} exec 2>&1 But running a script with the... (3 Replies)
Discussion started by: ckmehta
3 Replies

7. Shell Programming and Scripting

run commands within a script on certain days

Hi, please advise a script, something like this: If ; then do something else ( or for any other day of the week ) do otherthing fi Thanks (5 Replies)
Discussion started by: fed.linuxgossip
5 Replies

8. Shell Programming and Scripting

Run a shell script from one host which connext to remote host and run the commands

I want to write a script which would run from one host say A and connect to other remote host B and then run rest of commands in that host. I tried connecting from A host to B with SSH but after connecting to host B it just getting me inside Host B command prompt. Rest of the script is not running... (6 Replies)
Discussion started by: SN2009
6 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

10. Programming

code that reads commands from the standard i/p and executes the commands

Hello all, i've written a small piece of code that will read commands from standard input and executes the commands. Its working fine and is execting the commands well. Accepting arguments too. e.g #mkdir <name of the directory> The problem is that its not letting me change the directory i.e... (4 Replies)
Discussion started by: Phrozen Smoke
4 Replies
Login or Register to Ask a Question