Script invoked using "sh" is not executing. Urgent help required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script invoked using "sh" is not executing. Urgent help required
# 1  
Old 05-10-2011
Error Script invoked using "sh" is not executing. Urgent help required

Hi ,

I am new to shell scripting.

I am using Linux for doing scripting.

Below is my script, which takes 2 parameters as input.

test.sh has the below:
Code:
#!/bin/bash
. $HOME/.profile
gpg --yes --no-use-agent -r "$(eval echo \$$2_Var)" -e $1

1st parameter is command line string
2nd parameter is the name of the global variable initialised in .profile file.

if i execute this script using ". ./test.sh global filename" its running prefectly.
But when i try to execute as "sh test.sh global filename" its not executing and output is not created.

Code:
>echo $SHELL
/bin/bash

Can anyone help me on this. I need to run this script using "sh".

Thanks
Sesha

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 05-10-2011 at 10:00 AM.. Reason: code tags
# 2  
Old 05-10-2011
if you just type sh
do you end up in the shell?
or do you need to use bash?

Code:
root@M508 /> sh
#

or
Code:
root@M508 /> bash
#

the root@M508 is just in my screen...
should be different in yours
# 3  
Old 05-10-2011
Default SHELL is bash in my environment.


root->june$sh

root->/home/june/gpg> sh test.sh Inbound.dat Golf
: No such file or directoryme/june/.profile

The output file is not created, but when i try

root->/home/june/gpg> . ./test.sh Inbound.dat Golf
: No such file or directory


Its creating the output file (even though says No such file or directory)


Please help.

thanks
sesha
# 4  
Old 05-10-2011
is test.sh in the folder /home/june/gpg ?


try this:
Code:
#!/bin/bash
/$HOME/.profile
gpg --yes --no-use-agent -r "$(eval echo \$$2_Var)" -e $1

and then execute with the command:
./test.sh
when you are in the corrext folder

Last edited by metal005; 05-10-2011 at 10:18 AM..
# 5  
Old 05-10-2011
test.sh is available in /home/june/gpg

root->/home/june/gpg> ./test.sh Inbound.dat Golf
sh: ./test.sh: /bin/bash^M: bad interpreter: No such file or directory


Again failed.
# 6  
Old 05-10-2011
The display corruption in your error messages and the odd ^M suggest that your script file is not a unix format text file and contains carriage-return characters. Chances are that it has been edited with a Microsoft program such as "Notepad".

Please post the output from this command which is designed to make control codes visible. In a normal unix format text file the line terminator will be displayed as "$". Any extraneous carriage return characters will show as "\r".
Code:
sed -n l test.sh

# 7  
Old 05-10-2011
Paste the ouput of this

Code:
which bash
which sh

Code:
#!/bin/bash
. $HOME/.profile
gpg --yes --no-use-agent -r "$(eval echo \$$2_Var)" -e $1

regards,
Ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

3. Shell Programming and Scripting

How to fix this "Input is not UTF-8" while executing ksh script?

Hi, I have an automated script which have set of sqls but when i am trying to execute the automated script by using nohup command, it is throwing an error like "Input is not UTF-8" . And when i digged in to it, i am getting some "Â" character in the shell script. How to avoid this!? Thanks. (1 Reply)
Discussion started by: Samah
1 Replies

4. Shell Programming and Scripting

"if" Loop not working when executing script using cron

I am facing this weird issue where the script is working fine from the command line but when I am executing it from cron though it is working fine but the "if" loop is processing else part though I know that the if part of the logic is true and ideally the loop should execute the if portion. ... (3 Replies)
Discussion started by: sk2code
3 Replies

5. Shell Programming and Scripting

expect script not running in cron "Urgent"

I wrote a script to download the files from sftp location to local. while running the script manually its working fine. when i schedule the same in cron its not working.... :wall::wall: here is the script: #!/bin/bash ... (2 Replies)
Discussion started by: ganga39
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Emergency UNIX and Linux Support

Urgent Help on "Script Command" on a shell script

Dear All, I am trying to capture the terminal session using the script command. It works when i issue on that has a command. But it is not working on inside a shell script as it is expecting a exit command to come out. Even after I ran the script and it expects me type the exit command and not... (14 Replies)
Discussion started by: rrb2009
14 Replies

8. Shell Programming and Scripting

What is the difference executing a script with . in the front versus not putting a "."

Hi All, I know this has been discussed a lot but still I need some more answers. I am running this is ksh on AIX 5.3 I believe putting a "." in front of the script will start a new shell, is that correct?? I have a script which override some PATH variables and it does not do that... (3 Replies)
Discussion started by: Hangman2
3 Replies

9. Shell Programming and Scripting

when executing .sh script in telnet error "script not found"

Hi. i have written a wrapper script which inturn call the ftp child script in it. Now the problem is when i executing the same script in my script directory through putty it is getting executed successfully;where as through telnet i get an error "scripts not found" Can some one help me... ... (1 Reply)
Discussion started by: smiley
1 Replies

10. UNIX for Dummies Questions & Answers

when less invoked... what is the " log file "!?

:D I have been through the man pages and am not understanding the purpose of even what is a "Log File:"... I would like to be be able to access this application.. since it looks like something i could use but i am not sure what it is.. can some one clarify the matter.. and how to use it... thanx... (4 Replies)
Discussion started by: moxxx68
4 Replies
Login or Register to Ask a Question