Error while executing sh command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error while executing sh command
# 1  
Old 06-29-2012
Error while executing sh command

Hi,
I have 2 files temp1.sh and temp2.sh as follows:
===========
temp1.sh
===========
Code:
echo "session1"
sh temp2.sh
echo "exit session2 and enter session1"

=================================
=============
temp2.sh
=============
Code:
echo "session2"
sh 
echo "exit session2"

=================================
when i execute the temp1.sh script file (sh temp1.sh)
i need the output as
=============================
Code:
session1
session2
exit session2
exit session2 and enter session1

=============================
but i get the output as
==============
Code:
session1
session2

==============
After executing "sh" line in temp2.sh, it is coming out from the parent script(temp1.sh)Please help me on this....
thanks!

Last edited by Scrutinizer; 06-29-2012 at 07:22 AM.. Reason: code tags
# 2  
Old 06-29-2012
Is there any use of the sh command inside the temp2.sh ? If not remove that one and run the script.
# 3  
Old 06-29-2012
sh without any arguments will read commands from stdin. If you have not redirected stdin, it's waiting for your input at the terminal. Typing control-d will send EOF (end of file) and sh will exit, resuming the script.

Aside from possibly executing some startup files, sh < /dev/null should not do anything at all; when it attempts to read a command from stdin, it immediately sees EOF. Seems rather pointless.

Regards,
Alister
# 4  
Old 06-29-2012
Quote:
=============================
but i get the output as
==============

session1
session2
As alister explains, the free-standing sh has started a clean interactive shell. To get out of it, type exit or the control code for end-of-file (usually ctrl/D ) .
See stty -a to find out the control code for end-of-file on ypur terminal.
# 5  
Old 07-02-2012
Thanks for the replies!..

"command sh" is used to create a trusted sesion ID (which is called from .exe)to execute a batch file.. so sh command is necessary and cannot remove that line..is there any other way to get the exact o/p?(the code given above is just a dummy code..actual code is different)
# 6  
Old 07-02-2012
I have no idea what you're talking about. "Dummy code" is usually a waste of everyone's time.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Warn Before Executing Particular Command

I'm running CentOS 6.8 and use bash. I would like a warning to appear to the user who runs the command "service httpd restart" E.g. # service httpd restart are you sure y/n n # (or if y, the command executes). I looked into it a little but am not sure of the best approach. Aliases I... (2 Replies)
Discussion started by: spacegoose
2 Replies

2. Web Development

Error on executing soap request using Curl command

hi, i have curl command to POST a soap request to web service. I have a file (query.xml) which has all the soap message attached to it I just don't seem to be able to properly post it. curl command curl -s -H "Content-Type: text/soap+xml;charset=UTF-8" -H "SOAPAction:" -d @query.xml... (2 Replies)
Discussion started by: siramitsharma
2 Replies

3. UNIX for Advanced & Expert Users

Error executing sqlcmd command through UNIX

Hi All, I am trying to execute a set of sql statements in sql server 2008 using the sqlcmd command in unix and passing the query in the "input" parameter. It is giving me an error "incorrect syntax near 2014". The below statement is giving an error : declare date_val datetime, ... (4 Replies)
Discussion started by: Rahul Raj
4 Replies

4. Red Hat

Error while executing isql command on RHEL4

Hi, I am using RHEL4 and Oracle11g , my application requires odbc connection hence I modified ODBC.ini file and when I exceute isql commande I got the following error. isql: error while loading shared libraries: /opt/nastel/apwmq/odbc/lib/libodbc.so.1: requires glibc 2.5 or later dynamic... (4 Replies)
Discussion started by: roopalidalvi231
4 Replies

5. Red Hat

Error while executing isql command on RHEL4

Hi, I am using RHEL4 and Oracle11g , my application requires odbc connection hence I modified ODBC.ini file and when I exceute isql commande I got the following error. isql: error while loading shared libraries: /opt/nastel/apwmq/odbc/lib/libodbc.so.1: requires glibc 2.5 or later dynamic... (1 Reply)
Discussion started by: roopalidalvi231
1 Replies

6. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

7. AIX

Error while executing command in aix box

Hi Folks I get the below error in my aix box. Im not sure if this is an AIX issue or a TWS issue. Please advice me cbspsdb01:/opt/TWS/bin # ./conman status exec(): 0509-036 Cannot load program ./conman because of the following errors: 0509-150 Dependent module... (6 Replies)
Discussion started by: newtoaixos
6 Replies

8. Shell Programming and Scripting

cd command not executing in if else loop

Hi, I am executing below script s1=`pwd` s2=/space if then echo "done" else echo "mistake" cd /tmp fi I am not able to migrate to /tmp directory if the condition is not true.However mistake is being printed.Means cd command is not working here.All other commands except cd are... (3 Replies)
Discussion started by: d8011
3 Replies

9. Shell Programming and Scripting

Error executing shell command from a perl script

Hi Gurus, I've a find command that gets the list of files from a source directory where the extension is not html, xml, jsp, shtml or htaccess. The below find command runs fine from the command prompt or in a shell script. I need to eventually run it in a PERL script and am getting the... (5 Replies)
Discussion started by: voorkey
5 Replies

10. Shell Programming and Scripting

error while executing the mail command

Hi, I am getting an error while executing the mail command.... It says saved letter in dead.letter even though the email id id correct . Please do help.. Madhu (2 Replies)
Discussion started by: madhumathikv
2 Replies
Login or Register to Ask a Question

Featured Tech Videos