Assigning system command's output to variable

前端 未结 6 1202
梦毁少年i
梦毁少年i 2020-11-28 04:55

I want to run the system command in an awk script and get its output stored in a variable. I\'ve been trying to do this, but the command\'s output always goes t

6条回答
  •  时光说笑
    2020-11-28 05:40

    You can use this when you need to process a grep output:

    echo "some/path/exex.c:some text" | awk -F: '{ "basename "$1"" |& getline $1; print $1 " ==> " $2}'
    

    option -F: tell awk to use : as field separator

    "basename "$1"" execute shell command basename on first field

    |& getline $1 reads output of previous shell command in substream

    output:
    exex.c ==> some text
    

提交回复
热议问题