Bash - Initialize variable to output of command “permission denied”

前端 未结 2 864
有刺的猬
有刺的猬 2021-01-27 00:28

I\'m writing a small bash script to get the number out of each file name. For example the file name helloworld1.txt would produce 1.

When attem

相关标签:
2条回答
  • 2021-01-27 00:56

    You have missed echo here. The line

    i=`$f | tr -dc '[0-9]'`
    

    should be

    i=`echo $f | tr -dc '[0-9]'`
    
    0 讨论(0)
  • 2021-01-27 01:00

    The line in the loop without a subshell, pipe and additional process per file:

    i=${f//[^0-9]/}
    

    The parameter substitution removes all non-digits.

    0 讨论(0)
提交回复
热议问题