英文:
store diskspace value into variable
问题
du -sh $path | awk '{print $1}'
27G
英文:
Using du
command to get disk space, but only wanted the value, without the path. I am able to print using awk
, but how to store only the value into variable?
du -sh $path | awk '{print $1}'
27G
du -sh $path
27G $path
答案1
得分: 0
你可以使用一个变量来捕获并存储du
命令的输出:
disk_space=$(du -sh $path | awk '{print $1}')
echo "$disk_space"
英文:
You could use a variable to capture and store the output of du
command:
disk_space=$(du -sh $path | awk '{print $1}')
echo "$disk_space"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论