Get the last 4 characters of output from standard out

后端 未结 9 2011
借酒劲吻你
借酒劲吻你 2020-12-24 13:00

I have a script that is running and uses

lspci -s 0a.00.1 

This returns

0a.00.1 usb controller some text device 4dc9
         


        
9条回答
  •  清酒与你
    2020-12-24 13:57

    instead of using named variables, develop the practice of using the positional parameters, like this:

    set -- $( lspci -s 0a.00.1 );   # then the bash string usage:
    echo ${1:(-4)}                  # has the advantage of allowing N PP's to be set, eg:
    
    set -- $(ls *.txt)
    echo $4                         # prints the 4th txt file.  
    

提交回复
热议问题