Operating System - HP-UX
1824994 Members
2126 Online
109678 Solutions
New Discussion юеВ

Re: cntrl-d in shell script

 
SOLVED
Go to solution
Popy
Regular Advisor

cntrl-d in shell script

Hi,

What signal I will do the cntrl-d function in a shell script ?

I tried exit, exit 1, but no luck

Vijay
9 REPLIES 9
Mridul Shrivastava
Honored Contributor

Re: cntrl-d in shell script

Have you tried exit 0 ??
Time has a wonderful way of weeding out the trivial
Popy
Regular Advisor

Re: cntrl-d in shell script

tried exit 0 - no better
Mridul Shrivastava
Honored Contributor

Re: cntrl-d in shell script

what abt the quit ??

The ascii code for EOF(ctrl+D) is 0x1A, one way would be this:
perl -e "print \"\\x1A\";" | blah_command_to_recieve_it

Time has a wonderful way of weeding out the trivial
Dennis Handly
Acclaimed Contributor

Re: cntrl-d in shell script

Control D is EOF, it isn't a signal.

You can use "trap exit ..." but that will only work if you have an interactive shell. Or when you get to the end of your shell script.

Note: One shell script can read stdin N times, each terminated by the the EOF of the disk file or control D on a terminal.

>Mridul: The ascii code for EOF(ctrl+D) is 0x1A

No, the code is 0x04, see ascii(5). 0x1a, control-Z is the DOS EOF.

>one way would be this:
perl -e "print \"\\x1A\";" | blah_command_to_receive_it

This won't work. Control D is only valid for terminals. Not files nor pipes.
Popy
Regular Advisor

Re: cntrl-d in shell script

Thanks Dennis,

Let me tell you what I want to do, I have script which will send an Email if my ignite fails,

The script stops at this line, I want to come out from this line..

mailx -s "`hostname`: no tape loaded - ignite failed" vijay@xyc.com



Dennis Handly
Acclaimed Contributor

Re: cntrl-d in shell script

>The script stops at this line, I want to come out from this line:
mailx -s "`hostname`: no tape loaded - ignite failed" vijay@xyc.com

You need to provide stdin for the message body. You can either use echo, a here document or /dev/null:
$ echo hi | mailx -s "ho" ...
$ mailx -s "stuff" ... < /dev/null
$ mailx -s "more stuff" ... <mail body
EOF
Dennis Handly
Acclaimed Contributor
Solution

Re: cntrl-d in shell script

>ME: You need to provide stdin for the message body.

You can also provide the ignite error logs in the body:
$ mailx -s "more errors" ... < some-error-file
Popy
Regular Advisor

Re: cntrl-d in shell script

That did work....thanks Dennis. I've give the recover log as the input thereby avoided a keyboard interaction.

Cheers
Vijay
Popy
Regular Advisor

Re: cntrl-d in shell script

That did work....thanks Dennis. I've given the recovery log as the input, that avoided a keyboard interaction.

Cheers
Vijay