Read line by line in bash script

前端 未结 7 1916
暗喜
暗喜 2020-12-12 13:45

I want to do the following, read line by line of a file and use the value per line as params

FILE=\"cat test\"
echo \"$FILE\" | \\
while read CMD; do
echo $C         


        
7条回答
  •  醉话见心
    2020-12-12 14:33

    If you want to use each of the lines of the file as command-line params for your application you can use the xargs command.

    xargs -a  
    

    A params file with:

    a
    b
    c
    d
    

    and the file tr.py:

    import sys
    print sys.argv
    

    The execution of

    xargs -a params ./tr.py
    

    gives the result:

    ['./tr.py', 'a', 'b', 'c', 'd']
    

提交回复
热议问题