Bash 的循环是异步的吗?

2014-08-04 19:27:50 +08:00
 Axurez
apt-cache search php5- | while read line ; do name=$(echo $line | sed -E 's/(php5-[^ ]*).*/\1/g'); apt-get install $name ; done

本意是找出 php5- 开头的模块,然后提取名字,自动安装。

执行出来就只有第一个被安装了:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
php-pear
The following NEW packages will be installed:
php5-cgi
0 upgraded, 1 newly installed, 0 to remove and 46 not upgraded.
Need to get 4281 kB of archives.
After this operation, 18.2 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main php5-cgi amd64 5.5.9+dfsg-1ubuntu4.3 [4281 kB]
Fetched 4281 kB in 2s (1503 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LANG = (unset)
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
php5-cli - command-line interpreter for the php5 scripting language
php5-common - Common files for packages built from the php5 source
php5-curl - CURL module for php5
php5-dbg - Debug symbols for PHP5
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-gmp - GMP module for php5
php5-json - JSON module for php5
php5-ldap - LDAP module for php5
php5-mysql - MySQL module for php5
php5-odbc - ODBC module for php5
php5-pgsql - PostgreSQL module for php5
php5-pspell - pspell module for php5
php5-readline - Readline module for php5
php5-recode - recode module for php5
php5-snmp - SNMP module for php5
php5-sqlite - SQLite module for php5
php5-tidy - tidy module for php5
php5-xmlrpc - XML-RPC module for php5
php5-xsl - XSL module for php5
libphp5-embed - HTML-embedded scripting language (Embedded SAPI library)
php5-adodb - Extension optimising the ADOdb database abstraction library
php5-apcu - APC User Cache for PHP 5
php5-enchant - Enchant module for php5
php5-exactimage - fast image manipulation library (PHP bindings)
php5-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php5-gdcm - Grassroots DICOM PHP5 bindings
php5-gearman - PHP wrapper to libgearman
php5-geoip - GeoIP module for php5
php5-gnupg - wrapper around the gpgme library
php5-imagick - ImageMagick module for php5
php5-imap - IMAP module for php5
php5-interbase - interbase/firebird module for php5
php5-intl - internationalisation module for php5
php5-lasso - Library for Liberty Alliance and SAML protocols - PHP 5 bindings
php5-librdf - PHP5 language bindings for the Redland RDF library
php5-mapscript - php5-cgi module for MapServer
php5-mcrypt - MCrypt module for php5
php5-memcache - memcache extension module for PHP5
php5-memcached - memcached extension module for PHP5, uses libmemcached
php5-midgard2 - Midgard2 Content Repository - PHP5 language bindings and module
php5-ming - Ming module for php5
php5-mongo - MongoDB database driver
php5-msgpack - PHP extension for interfacing with MessagePack
php5-mysqlnd - MySQL module for php5 (Native Driver)
php5-mysqlnd-ms - MySQL replication and load balancing module for PHP
php5-oauth - OAuth 1.0 consumer and provider extension
php5-pinba - Pinba module for PHP 5
php5-ps - ps module for PHP 5
php5-radius - PECL radius module for PHP 5
php5-redis - PHP extension for interfacing with Redis
php5-remctl - PECL module for Kerberos-authenticated command execution
php5-rrd - PHP bindings to rrd tool system
php5-sasl - Cyrus SASL Extension
php5-stomp - Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP 5
php5-svn - PHP Bindings for the Subversion Revision control system
php5-sybase - Sybase / MS SQL Server module for php5
php5-tokyo-tyrant - PHP interface to Tokyo Cabinet's network interface, Tokyo Tyrant
php5-vtkgdcm - Grassroots DICOM VTK PHP bindings
php5-xcache - Fast, stable PHP opcode cacher
php5-xdebug - Xdebug Module for PHP 5
php5-xhprof - Hierarchical Profiler for PHP5
Selecting previously unselected package php5-cgi.
(Reading database ... 35071 files and directories currently installed.)
Preparing to unpack .../php5-cgi_5.5.9+dfsg-1ubuntu4.3_amd64.deb ...
Unpacking php5-cgi (5.5.9+dfsg-1ubuntu4.3) ...
Processing triggers for man-db (2.6.7.1-1) ...
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Setting up php5-cgi (5.5.9+dfsg-1ubuntu4.3) ...
update-alternatives: using /usr/bin/php5-cgi to provide /usr/bin/php-cgi (php-cgi) in auto mode
update-alternatives: using /usr/lib/cgi-bin/php5 to provide /usr/lib/cgi-bin/php (php-cgi-bin) in auto mode
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

Creating config file /etc/php5/cgi/php.ini with new version
php5_invoke: Enable module pdo for cgi SAPI
php5_invoke: Enable module pdo_mysql for cgi SAPI
php5_invoke: Enable module mysql for cgi SAPI
php5_invoke: Enable module mysqli for cgi SAPI
php5_invoke: Enable module opcache for cgi SAPI
php5_invoke: Enable module readline for cgi SAPI
php5_invoke: Enable module json for cgi SAPI

这段脚本的真实执行步骤是如何的?应该怎样改才能达到效果?
2278 次点击
所在节点    问与答
3 条回复
jings
2014-08-04 19:48:00 +08:00
echo " $( apt-cache search php5- | awk '{print $1}') " > file.txt &&while read line; do apt-get install $line; done < file.txt
用我的好像也是这样的结果。。
iptux
2014-08-04 19:54:23 +08:00
为啥要用 while?循环体当然是每次循环都会执行

$ apt-cache search php5- | awk '{print $1}' | xargs sudo apt-get install
Axurez
2014-08-08 16:17:00 +08:00
@iptux 有用,
但是第一次执行的时候,还是只安装了一个包;不断重新执行好多次,才终于正常。这是为什么呢?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/126096

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX