Shell Scripting (prompt off)


 
Thread Tools Search this Thread
Operating Systems AIX Shell Scripting (prompt off)
# 8  
Old 10-11-2013
Quote:
Originally Posted by kwliew999
I just keep on digging how to send in a "y" for whatever return on screen.
As you might need this for other occasions here is how you do it:

Short introduction to I/O redirection

You can picture any process in UNIX to be like a garden hose: something goes in on top, something goes out on the bottom. You can daisy-chain processes in a pipeline with the "|"-symbol, which simply means "connect the output of one process with the input of the other".

Now suppose you want to produce a "y". You could use (try out the following out, it is all non-descructive):

Code:
print - "y"

So this is a process which takes nothing in and sends something (a "y") to its output. Let us construct a process processing some input (we could use your compress-process, but we want something we can watch more closely):

Code:
#! /bin/ksh

typeset input=""
while : ; do
     input=""
     echo "enter something: " ; read input
     case $input in
          y)
               echo "you entered a 'y'. Exiting...."
               exit
               ;;
          *)
               echo "you entered '$input'. Enter 'y' to exit."
               ;;
     esac
done

Save this to a file "logger.ksh" and make it executable. Try it out on its own (it can be tricked by keyboard artistics like CTRL-C, but enter something "normal" and it does what you would expect - exit on "y" and start over on anything else).

Now call

Code:
 print - "y\n" | ./logger.ksh

and you will notice that this is the same as if you would have entered it by keyboard. Lets do another test. In case you wonder about the "\n" - these are just codes for the ENTER-key on your keyboard:

Code:
# print - "a\nb\ny\n" | ./logger.ksh
enter something: 
you entered 'a'. Enter 'y' to exit.
enter something: 
you entered 'b'. Enter 'y' to exit.
enter something: 
you entered a 'y'. Exiting....

Per default the input of a process is taken from the keyboard - like the shell (which is just another process), which listens there and takes up what you type. But by redirecting the input you can make the process take its input from any other source, just like you can make it put its output to somewhere else (like a file) instead of the screen it would normally output to. You can even use a file for input:

Code:
process < /path/to/some/file

To stay in the garden-hose picture i used above: you plug the respective end of the hose to some device, which can provide/store something to put through the hose - files, devices (like keyboards for input, screens for output) or other processes.

I hope this helps.

bakunin

Last edited by bakunin; 10-11-2013 at 09:07 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting password prompt for restarting Jboss application

Hi When I do on console a stop, the script prompts for password > stop_idm_suite.sh Suite system password:Here experct of the shell script stop_idm_suite.sh DoIt() { # prompt System password echo "" ${BMC_JAVA_HOME}/java -Didm.suite.home=${BMC_IDM_SUITE_HOME} -classpath... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

2. Programming

scripting for recieving a prompt

I have to run a script provided by a vendor. Its an executable so I can't change it. basically after I call it it prompts me for a password. The script does not provide a way for me to pass a password with the command that calls the script. I would like to automate running this script from... (5 Replies)
Discussion started by: guessingo
5 Replies

3. Shell Programming and Scripting

Changing the shell prompt

Hi, I want to change the shell prompt, using the cd command. I have a shell prompt like this - p78-mfx(dgaw1078/9781)$ Now i do this - p78-mfx(dgaw1078/9781)$ cd log4j here the shell prompt should change like this - p78-mfx(dgaw1078/9781)log4j$ (6 Replies)
Discussion started by: arunkumarmc
6 Replies

4. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

5. UNIX for Dummies Questions & Answers

how much we can pipe in shell prompt ?

Hi All experts, I was asked some questions of late & i was not aware of these. 1Q. how much we can pipe in shell prompt ?2Q. how many arguments we can pass in shell script & how to print that ? (eg, if i want to know what I passed in 11th Argument) ( for 3rd argument we can do echo $3, but I think... (7 Replies)
Discussion started by: adc22
7 Replies

6. UNIX for Advanced & Expert Users

Weird in Shell Prompt

Hi, I saw something in weird in Shell prompt. I did the following steps 1) Typed ls -l and pressed ESC without entering 2) Typed "v" (please notice that I did not type "i" after "v"), which opened vi editor 3) I see the "ls -l" command that I typed in shell prompt 4) Without modifying... (6 Replies)
Discussion started by: bobbygsk
6 Replies

7. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies

8. UNIX for Dummies Questions & Answers

shell specific prompt

currently, I set my prompt in my .cshrc file as: set prompt = "%B%h %m %P %/ \n% " I have to use certain shells for some specific tasks and would like to set different prompts depending on the type of shell that I am using. Any advice? Thanks (3 Replies)
Discussion started by: dranNfly
3 Replies

9. UNIX for Dummies Questions & Answers

prompt in sh shell

Hi, I´m using SCO Unix 5.0.5 and I want to configure de variable PS1, so when I type the command: cd /etc/ the prompt shows /etc/_> Is that possible with sh shell? I´ll appreciate your help. Thanks, a Happy New Year! (1 Reply)
Discussion started by: diegoe
1 Replies

10. UNIX for Dummies Questions & Answers

No shell prompt?

When I login to a specific machine (running Solaris 2.8; actually serveral machines behave this way), with a known good account, I don't get any shell prompt, and no screen responses to various commands such as ID and PWD. Any ideas on what is causing this, and how to change this behavior? (2 Replies)
Discussion started by: Mufasa
2 Replies
Login or Register to Ask a Question