How to pass multiple keystrokes or y to a command in Centos or Redhat Linux ?

In this post, we will check how to automate entering of multiple y’s to a shell command or script.

This tip is very useful to sometimes automate few install scripts/commands.

1. hello variable gets the output of yes command i.e. “y”

[root@nglinux testdir]# yes | read hello ; echo $hello
[root@nglinux testdir]# 


2. yes will pass y when yum command prompts for answer.

[root@nglinux testdir]# yes | yum reinstall bc
Failed to set locale, defaulting to C
Loaded plugins: auto-update-debuginfo, fastestmirror, refresh-packagekit, security
Setting up Reinstall Process
Loading mirror speeds from cached hostfile
 * base:
 * epel:
 * epel-debuginfo:
 * epel64:
 * extras:
 * updates:
Resolving Dependencies
--> Running transaction check
---> Package bc.i686 0:1.06.95-1.el6 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

 Package          Arch               Version                        Repository          Size
 bc               i686               1.06.95-1.el6                  base               106 k

Transaction Summary
Reinstall     1 Package(s)

Total download size: 106 k
Installed size: 204 k
Is this ok [y/N]: Downloading Packages:
bc-1.06.95-1.el6.i686.rpm                                             | 106 kB     00:03     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : bc-1.06.95-1.el6.i686                                                     1/1 
  Verifying  : bc-1.06.95-1.el6.i686                                                     1/1 

  bc.i686 0:1.06.95-1.el6                                                                    

[root@nglinux testdir]# 


0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments