V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
holinhot
V2EX  ›  Linux

shell 怎么逐行从 txt 读入变量

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