Operating System - HP-UX
1838656 Members
3607 Online
110128 Solutions
New Discussion

Re: "Return" in a shell script.

 
Mike_21
Frequent Advisor

"Return" in a shell script.

How do I implement a return in a shell script? I want this to happen automatically. For example, I execute a command and want 2 "returns" to happen.....
9 REPLIES 9
A. Clay Stephenson
Acclaimed Contributor

Re: "Return" in a shell script.

Hi Mike:

Your question is very unclear. Do you want to exit with a given value (e.g) exit 2; do you want to print values to stdout?; or do you want to echo Carriage Returns via echo "\r\r\c"?
If it ain't broke, I can fix that.
Mike_21
Frequent Advisor

Re: "Return" in a shell script.

Ok, for example I have a command the requires you to hit the enter key. I am planning to cron the job, so how do I get the script to do this automatically???
James R. Ferguson
Acclaimed Contributor

Re: "Return" in a shell script.

Hi Mike:

Do you want/mean "return" as in linefeed?...then:

# echo "bye!\n"

Or do you mean 'break' one or more time from a loop control?

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: "Return" in a shell script.

Hi Mike:

...like this:

# echo "Press ENTER when ready!"
# read BITBUCKET

Regards!

...JRF...
Mike_21
Frequent Advisor

Re: "Return" in a shell script.

he..he.. I am making this confusing......

I mean at a certain point in this script, the script is waiting for the user to hit the "enter" key, I want this action to be aoutmatic!
A. Clay Stephenson
Acclaimed Contributor

Re: "Return" in a shell script.

Hi agian Mike:

Plan B. Look into a utility called 'Expect'. You can get it from any of the HP-UX Porting Centre's. With Expect, you can specify patterns to look for and then the appropriate response. If all you need are a couple of LF's CR's then simply echo will work just fine.

Clay
If it ain't broke, I can fix that.
Darrell Allen
Honored Contributor

Re: "Return" in a shell script.

Hi Mike,

If you're certain you want to always answer the replies with :

process <

EOF

Hopefully this show up as 2 blank lines between the start of input redirection (<
Put nothing else on between these 2 lines. The ending EOF needs to start in column 1.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Kenny Chau
Trusted Contributor

Re: "Return" in a shell script.

Hi,

Maybe you can try this:

echo "Press enter to continue..."
ans=`line -t 5`

It will continue after 5 seconds without press the enter key.

Hope this helps.
Kenny.
Kenny
Bill Hassell
Honored Contributor

Re: "Return" in a shell script.

The answer depends entirely on the command that requires the two returns. If the program understands stdin, then you could redirect stdin to be two carriage returns. If the process needs yes or no or something else, you can redirect the output of yes (hint: man yes) to the program.

If the program does not understand redirected stdin, then the freeware program expect may be a solution. Don't try to test the command in the script until you get it to work from the command line. And be sure that if the program requires a special environment, it must be set in the script (cron has almost nothing in the environment).


Bill Hassell, sysadmin