简体   繁体   English

使用'fdisk -l |的输出 grep Disk”放入“ if”语句

[英]Using the output of 'fdisk -l | grep Disk' to put in an 'if' statement

My goal is to use the finding from 'fdisk -l | 我的目标是使用来自'fdisk -l |的发现。 grep Disk' to run an if statement based off what it finds. grep Disk”可根据发现的内容运行if语句。 Basically, my school has 2 harddrive sizes, 320GB and 500GB. 基本上,我的学校有2种硬盘大小,分别为320GB和500GB。 If it finds a 320GB drive, it should continue with the partition. 如果找到320GB驱动器,则应继续使用该分区。 If it finds a 500GB it should stop. 如果找到500GB,则应停止。

$ fdisk -l | grep Disk
Disk /dev/sda: 320.1 GB, 320072933376 bytes
Disk identifier: 0x00027998

I want to "grab" that 320. Can that be done using awk or maybe a head/tail -c? 我想“抓住”320。可以使用awk或头/尾-c来完成吗? I'm extremely new to shell script. 我对Shell脚本非常陌生。 Thanks! 谢谢!

Try this: 尝试这个:

size=$(fdisk -l | awk '$1=="Disk" && $2 ~ /^\/dev\/.*/ {print $3}')
if (( ${size%.*} == 320 )); then ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM