Execute shell script without using sh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute shell script without using sh
# 1  
Old 04-19-2012
Execute shell script without using sh

Hi Experts,

I want to execute shell script(on HP-UX) wihout specifying interpreter.

For e.g generally we use following command to execute shell

Code:
sh test.sh

but I want to execute it as

Code:
 
test.sh

currently if I execute directly it as test.sh it is giving error Commnd Not Found.

However on another HP-UX box I am able to execute it without specifying sh and it is not giving any error.

Are there any environment variables that needs to be set?
# 2  
Old 04-19-2012
It can't find it. You have to issue ./test.sh. It works on the other system most probably because the PATH variable contains a . or the directory you are in, which might be less probably.
Use following command to check what is in PATH:
Code:
echo $PATH

There might be a dot in it.
# 3  
Old 04-19-2012
try running head test.sh on the script for which this works, the "shebang" line at the head of the script (hash bang, "#!" ) defines the interpreter to use, thus aq file starting #! /bin/bash will be run under the bash interpreter if the file is made executable and called.

updateWhat zaxxon said above, your PATH variable is what you were looking for.

Last edited by Skrynesaver; 04-19-2012 at 10:00 AM.. Reason: Coz I misread the question
# 4  
Old 04-19-2012
The script needs to be executable, see man chmod.
# 5  
Old 04-19-2012
Hi skrynesaver,

Thanks for the reply.

I tried that also as shown in below code. But still it is giving the same error, command not found Smilie

Code:
% more test.sh
#!/bin/sh
echo "hi"
#
 
% test.sh
test.sh: Command not found.
%

---------- Post updated at 08:02 AM ---------- Previous update was at 08:00 AM ----------

Hi Scrutinizer,

Thanks for the reply.

Script already has executable permisson.

---------- Post updated at 08:04 AM ---------- Previous update was at 08:02 AM ----------

Hi zaxxon

So If I add my directory(directory where my shell resides) to PATH env variable,will I be able to execute it without using sh ?

I will check the PATH variable on the server on which it is running fine and post the result here.

Last edited by methyl; 04-19-2012 at 10:02 AM.. Reason: please use code tags
# 6  
Old 04-19-2012
Got it!
I can only get that "Command not found" message from /usr/bin/csh.
Your account is set up incorrectly for this job and your default shell is /usr/bin/csh not /usr/bin/sh. Either that or you should be writing the script in csh. Perhaps your Mentor or Tutor can advise.

As a quick temporary fix, first type sh at the csh prompt before trying any Bourne Shell commands.

Most posters on this board would recommend learning Bourne-type Shell scripting and avoid the "C Shell" because no system scripts are written in "C Shell" on any modern unix or Linux system.

In csh the equivalent of the Bourne $PATH environment variable is the $path variable. Type set at the command prompt to see the values of your environment variables (in either Shell).

Last edited by methyl; 04-19-2012 at 10:28 AM..
# 7  
Old 04-19-2012
I think the best advice was given in zaxxons second sentence: call the script by specifying its path. When you issue ./test.sh you specify a relative path with the dot standing for your current directory.
Adding the current directory (dot) to your path-variable can have undesired effects (imagine you mistype something and your current directory contains some 10.000 files...), but using paths is good practice anyway, especially when it comes to automate something using cron.
@methyl: unfortunately SAP uses csh for its os-users, at least the last time I had to work with it...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

2. Shell Programming and Scripting

How to execute one shell script after execution of another shell script?

I have a master shell script master.sh which will invoke 2 shell scripts (test1.sh,test2.sh). Both of these shell scripts will execute stored procedure. I will invoke test1.sh, test2.sh respectively. Now both of these scripts are executing parallel. But i want to invoke the 2nd script(test2.sh)... (3 Replies)
Discussion started by: vel4ever
3 Replies

3. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

4. UNIX for Dummies Questions & Answers

can't execute a shell script

Hi all, As i want to know how the shell command "nohup" worked.I logged in as the user named vincent through Gnome.Then i press ctrl+atl+F1 changed into a console and logged in as another user named kinsley.The user "kinsley" is added by me with "useradd",and now there's no HOME directory for... (6 Replies)
Discussion started by: homeboy
6 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

7. Shell Programming and Scripting

not able to execute shell script

HI, bash-2.05# more mysqlstoporaclestart.sh #!/bin/sh mysqladmin -u root -pengineer shutdown su - oracle -c "bash /export/home/oracle/oracle.sh" bash-2.05# more /export/home/oracle/oracle.sh /oracle/bin/sqlplus "/as sysdba"<< EOF startup nomount... (2 Replies)
Discussion started by: prakash.gr
2 Replies

8. UNIX for Dummies Questions & Answers

To call/execute a shell script from a shell script

Hi , I have 4 shell scripts a.ksh b.ksh -> depends on a.ksh success -> log into b.log c.ksh -> depends on b.ksh success -> log into c.log d.ksh -> depends on c.ksh success -> log into d.log I will have to write main.ksh ( execute a.ksh , log into a.log if a.ksh= success, execute... (1 Reply)
Discussion started by: konark
1 Replies

9. UNIX for Dummies Questions & Answers

Execute Shell Script

Hi all, I am begginer of UNIX . I dont know if i have a script written in korn shell with .ksh extention . If i want to execute that how can i do that? Can anybody suggest the best book to learn korn shell scripting. Thanks sam71 (1 Reply)
Discussion started by: sam71
1 Replies

10. Shell Programming and Scripting

How to execute shell Script?

I am new to UNIX , Can any one let me know how to execute shell script (i.e which command I have to use for the same). Any help would be appreciated. Thanks siva mymvs999@yahoo.com (3 Replies)
Discussion started by: siva
3 Replies
Login or Register to Ask a Question