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
y
[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: mirror.atlantic.net
 * epel: mirror.csclub.uwaterloo.ca
 * epel-debuginfo: mirror.csclub.uwaterloo.ca
 * epel64: mirror.csclub.uwaterloo.ca
 * extras: centos.mirror.constant.com
 * updates: centos.mirror.constant.com
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
=============================================================================================
Reinstalling:
 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 

Installed:
  bc.i686 0:1.06.95-1.el6                                                                    

Complete!
[root@nglinux testdir]# 

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments