Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
atom
V2EX  ›  Linux

“$()”是什么含义

  •  
  •   atom · May 7, 2013 · 4932 views
    This topic created in 4948 days ago, the information mentioned may be changed or developed.
    看到过一个快速生成数组的技巧
    array=($(cat file))

    里面的“$()”是什么含义呢?
    5 replies  •  1970-01-01 08:00:00 +08:00
    bao3
    bao3
    May 7, 2013❤️1
    1
    表示将 cat file 执行的结果作为变量
    huangzxx
    huangzxx
    May 7, 2013❤️1
    2
    # file 的内容
    $ cat file
    a b c

    # 转成数组
    $ array=($(cat file))

    # array 所有元素
    $ echo ${array[@]}
    a b c

    # array 第一个元素
    $ echo ${array[1]}
    a

    # 第二个
    $ echo ${array[2]}
    b

    # 第三个
    $ echo ${array[3]}
    c
    atom
    atom
    OP
    May 7, 2013
    3
    @bao3
    确实是一种新的变量赋值方式。和``一样。
    liwei
    liwei
    May 7, 2013❤️1
    4
    man bash

    看 "Command Substitution" 这一节。
    bao3
    bao3
    May 7, 2013
    5
    @atom no,和 ``有一点点区别的,通常都可以通用。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   953 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 19:48 · PVG 03:48 · LAX 11:48 · JFK 14:48
    ♥ Do have faith in what you're doing.