Linux shell in while with read from keyboard input

Source: Internet
Author: User

The system is Ubuntu 14.04 64bit, previously wanted to install stream to play dota2, but eventually did not succeed. Because stream is only 32bit, a large number of 32bit libraries are installed when the stream is installed. Delete the stream, these libraries have been no tube, today suddenly whim, want to clean up the system, the unnecessary 32bit library to kill.

Dpkg-l | grep "i386" look, 32bit library too many, a knock sudo apt-get purge xxx Obviously a bit tired, analyzed the output, the format is probably as follows:

RC  libkrb5support0:i386   1.12+dfsg-2ubuntu4   i386  MIT Kerberos Runtime Libraries-support Library

The 2nd column is the package name, the 4th is the platform, so decided to write a script to delete:

#!/bin/SH#rc libkrb5support0:i3861.12+dfsg-2ubuntu4 i386 MIT Kerberos Runtime Libraries-Support library# #pks= ' Dpkg-l |grep "i386"|awk '{print $2,$4}'' tmp="Tmp.file"Echo "$pks">$tmp whileRead Line Doname=`Echo$line |awk '{print $}'' Platform=`Echo$line |awk '{print $}'`    # if[ == ]inchBash,bufinchDashif[ = ]    if["$platform"="i386"]; Then        sudoapt-Get purge $namefi Done<$tmpRM-RF $tmpexit0

This script is generally nothing wrong, but when you execute sudo apt-get purge $name This line, the system asks whether to delete it. But then there is no opportunity to enter, but to abort the execution directly.

[Email protected]:~$./rm_i386_package. SH Reading Package List ... Completing the dependency tree that is analyzing the package is       reading state information ... Complete the       following packages will be "uninstalled":  libdrm-radeon1:i386*001306    Additional space of 0 B. Do you want to continue? [Y/n] aborts execution.

Bulk Delete Software This operation, of course, a confirmation, can not add a parameter default execution AH.

Look up the information, probably say

 while Read Line  Do # XXX  Done < $file

This redirects the read instruction to the file $file, when the call to read in while takes a row in the file as input. Therefore, read is redirected to the terminal in the while. The above script modifies a line slightly:

sudo apt-get purge $name </dev/tty

This will be OK.

Linux shell in while with read from keyboard input

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.