简体   繁体   English

如何在bash脚本中执行此操作

[英]how to do this in bash script

in Linux, suppose mount command return this 在Linux中,假设mount命令返回此

/dev/sdc1 on /media/ELF (^-^)V type vfat 
/dev/sdb1 on /media/PENDRIVE type vfat 

all I want to do is get all mount point of my usb disk. 我要做的就是获取USB磁盘的所有挂载点。

I did that already, using combination of grep and sed I can get these: 我已经做到了,使用grep和sed的结合,我可以得到这些:

/media/ELF (^-^)V
/media/PENDRIVE

the problem is, when I do for loop in bash, those text will become 3 part instead of 2 parts , I mean : 问题是,当我在bash中进行循环时,这些文本将变成3部分而不是2部分,我的意思是:

suppose I put the result of those text in LIST 假设我将这些文本的结果放在LIST中

for list in $LIST; do
    echo $list
done;

the result of that for loop becomes for循环的结果变为

/media/ELF
(^-^)V
/media/PENDRIVE

how to handle this issue? 如何处理这个问题? or are there any easier ways to get mount point of my usb disk? 还是有更简单的方法来获取USB磁盘的挂载点?

Thanks 谢谢

If you've already extracted the mountpoint paths and the only issue is to process them in a loop: 如果您已经提取了安装点路径,那么唯一的问题就是循环处理它们:

while read -r mountpoint; do
  echo "[$mountpoint]"
done < <(mount | grep /media | grep uhelper=udisks | sed -e 's/\/dev\/.*on //g' -e 's/ type .*//g')

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

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