The following small series will bring you an article on the linuxshell while using read to input from the keyboard. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the system in ubuntu 14.04 64bit. We wanted to install Stream to play dota2, but it was not successful. Since Stream only has 32bit, a large number of 32bit libraries are also installed during Stream installation. After the Stream is deleted, these databases have never been taken care of. Today, we have a sudden whim and want to clean up the system and kill unnecessary 32bit databases.
Dpkg-l | grep "i386": check that there are too many 32-bit databases. it is a little tired to knock sudo apt-get purge xxx one by one. after analyzing the output,
The format is roughly as follows:
rc libkrb5support0:i386 1.12+dfsg-2ubuntu4 i386 MIT Kerberos runtime libraries - Support library
The 2nd column is the package name and the 4th column is the platform, so I decided to write a script to delete it:
#!/bin/sh #rc libkrb5support0:i386 1.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 while read linedo name=`echo $line | awk '{print $1}'` platform=`echo $line | awk '{print $2}'` # if [ == ] in bash,buf in dash,if [ = ] if [ "$platform" = "i386" ];then sudo apt-get purge $name fidone < $tmp rm -rf $tmp exit 0
This script is basically correct, but when executing the sudo apt-get purge $ name line, the system asks whether to delete it. However, there is no chance to enter it, but the execution is aborted directly.
Xzc @ xzc-HP-ProBook-4446s :~ $. /Rm_i1__package.sh is reading the package list... the dependency tree of the software package being analyzed is reading status information... libdrm-radeon1: i386 * has been upgraded to 0, new to 0, to uninstall 1, and 306 have not been upgraded. After decompression, the extra space of 0 B is consumed. Do you want to continue? [Y/n] abort execution.
To delete software in batches, you must confirm the operation. you cannot add a parameter for default operation.
I checked the information, which probably means
while read linedo# xxxdone < $file
In this way, the read command will be redirected to the file $ file. then, calling read in while Will directly take a row in the file as the input. Therefore, you must redirect the read to a terminal in the while clause. The above script slightly modifies a line:
sudo apt-get purge $name < /dev/tty
In this case, OK.
The above is a small series of linux shell for everyone to use read to input all the content from the keyboard while, I hope you will support a lot of PHP Chinese network ~
For more information about how to use the read function in linux shell while to input data from the keyboard, see PHP!