Assing a variable and use it inside of if statement shell scripting

后端 未结 2 1084
囚心锁ツ
囚心锁ツ 2021-01-20 14:08

I am new to shell scripting and trying to make a few small scripts. I got stuck when i tried to write if condition. In the code below i am trying to get the $5 value from df

2条回答
  •  春和景丽
    2021-01-20 14:55

    Assuming you're using GNU tools, you can narrow the df output to just what you need:

    pct=$( df --output=pcent / | grep -o '[[:digit:]]\+' )
    if [[ $pct -gt 60 ]]; then ...
    

提交回复
热议问题