How To Script "Yes" When Installing Programs on Linux?

Installing programs on Linux often requires user interaction, such as agreeing to license terms or confirming installation options. To automate this process, you can use scripts that automatically provide the desired responses. This article explains how to script "yes" responses when installing programs on Linux using command line tools.

Using the "yes" Command

The yes command is a built-in utility that continuously outputs a specified string, making it perfect for automated responses to installation prompts.

Basic Usage

The yes command is part of the coreutils package, which is pre-installed on most Linux distributions. To use it, simply type yes followed by the string you want to output repeatedly

$ yes "I agree"
I agree
I agree
I agree
...

The command will continue outputting until interrupted with Ctrl+C. When used without arguments, yes defaults to outputting "y".

Piping "yes" to Installation Commands

To automate installation responses, pipe the yes command output to your installation command using the | symbol

$ yes | sudo apt install program-name
$ yes | sudo yum install program-name
$ yes | sudo pacman -S program-name

This sends continuous "y" responses to all prompts, effectively accepting defaults and confirmations automatically.

Using Package Manager Flags

Most package managers provide built-in options to assume "yes" responses, which is more efficient than using the yes command

Package Manager Flag Example
apt (Debian/Ubuntu) -y, --yes sudo apt install -y program-name
yum (Red Hat/CentOS) -y sudo yum install -y program-name
dnf (Fedora) -y sudo dnf install -y program-name
pacman (Arch) --noconfirm sudo pacman -S --noconfirm program-name

Using "expect" for Complex Interactions

For installations requiring complex responses beyond simple "yes/no" answers, use the expect utility to create sophisticated automation scripts.

Installing Expect

$ sudo apt install expect          # Debian/Ubuntu
$ sudo yum install expect          # Red Hat/CentOS
$ sudo dnf install expect          # Fedora

Creating an Expect Script

#!/usr/bin/expect -f
set timeout 30
spawn ./installer
expect "Do you accept the license agreement? (yes/no)"
send "yes\r"
expect "Enter installation directory:"
send "/opt/myprogram\r"
expect "Install additional components? (y/n)"
send "y\r"
expect eof

Key components of an expect script

  • spawn Starts the target program

  • expect Waits for specific text patterns

  • send Sends responses (use \r for Enter key)

  • set timeout Prevents hanging on unexpected prompts

Advanced Techniques

Using Here Documents

For programs that read multiple lines of input, use here documents

$ sudo ./installer << EOF
yes
/opt/installation/path
yes
EOF

Combining Methods

$ echo -e "yes\nyes<br>/opt/myapp" | sudo ./installer

Troubleshooting

  • Buffering issues Some programs buffer input; add stdbuf -o0 before commands

  • Timing problems Use sleep commands between responses in scripts

  • Exact pattern matching In expect scripts, ensure prompts match exactly including spacing and punctuation

  • Debug expect scripts Use expect -d script.exp to see detailed execution flow

Conclusion

Automating Linux program installations saves time and ensures consistency across deployments. Use package manager flags like -y for simple cases, the yes command for basic automation, and expect scripts for complex interactive installations. Choose the method that best fits your specific automation needs.

Updated on: 2026-03-17T09:01:38+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements