V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Axurez
V2EX  ›  问与答

Bash 的循环是异步的吗?

  •  
  •   Axurez · 2014-08-04 19:27:50 +08:00 · 2297 次点击
    这是一个创建于 3783 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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

    这段脚本的真实执行步骤是如何的?应该怎样改才能达到效果?
    3 条回复    2014-08-08 16:17:00 +08:00
    jings
        1
    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
        2
    iptux  
       2014-08-04 19:54:23 +08:00
    为啥要用 while?循环体当然是每次循环都会执行

    $ apt-cache search php5- | awk '{print $1}' | xargs sudo apt-get install
    Axurez
        3
    Axurez  
    OP
       2014-08-08 16:17:00 +08:00
    @iptux 有用,
    但是第一次执行的时候,还是只安装了一个包;不断重新执行好多次,才终于正常。这是为什么呢?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3388 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:53 · PVG 08:53 · LAX 16:53 · JFK 19:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.