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

shell 怎么逐行从 txt 读入变量

  •  
  •   holinhot · May 7, 2015 · 3788 views
    This topic created in 4203 days ago, the information mentioned may be changed or developed.

    1.txt 内容
    my
    you
    123
    12321

    写个rm -rf /home/文本内的文件名

    让他循环删除文本内的文件名

    10 replies  •  2015-05-08 17:20:21 +08:00
    sagrada
    sagrada
    May 7, 2015
    1
    while read line ; do
    echo $line
    done < $file
    yetone
    yetone
    May 7, 2015
    2
    cat 1.txt | xargs -i rm -rf /home/{}
    yetone
    yetone
    May 7, 2015
    3
    BTW, rm -rf 要慎用 = =
    phx13ye
    phx13ye
    May 7, 2015
    4
    lines=`cat 1.txt`
    for i in lines; do echo $i;done
    illuz
    illuz
    May 7, 2015❤️1
    5
    不怕有空行然后把 home 目录都删了吗
    Csineneo
    Csineneo
    May 7, 2015
    6
    eval `sed 's#^#rm -rf /home/#' 1.txt`
    nicai000
    nicai000
    May 7, 2015
    7
    IFS=$'\n'
    for orig in `cat foo.txt`
    do
    blah
    done
    iehp
    iehp
    May 8, 2015
    8
    @illuz 曾经 rm -rf /home/ 的含泪路过。。
    holinhot
    holinhot
    OP
    May 8, 2015
    10
    @illuz 除过空行和空格了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4019 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 08:11 · PVG 16:11 · LAX 00:11 · JFK 03:11
    ♥ Do have faith in what you're doing.