Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I write a command line answer

Status
Not open for further replies.

koeicjm

Programmer
Sep 12, 2001
73
JP
how can I write a command line answer, for example if I want to make a script to input a password for a user,
just like this "passwd pgsql" , but I want to write the password in the script .
 
I means how can I input the y y in shell script , not input
by user
$ createuser talky2
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) y
 
This should work for your example:

Code:
$ createuser talky2 <<EOF
y
y
EOF

Using this method you must specify ALL input needed by the command. If the command
Code:
createuser
read more than two answers all answers following the two 'y' will be empty.
 
Hi,
YES is a program which will echo by default a 'y' everytime there is a READ pending.

so you could do.....


yes | createuser talky2

if you want something other than a 'y' echo you can say....

yes 'd'

and it will echo a d. If you need to echo more than a single reply than I suggest you use the << EOF method described above.

 
But it can not run .

#passwd chen<<EOF
password
password
EOF
 
Hi,
It is possible that passwd doesn't read from STDIN for security reasons. It is possible that it opens it own IO stream.

----
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top