掛載來自 stdin 的 unionfs (或 aufs)分支?

掛載來自 stdin 的 unionfs (或 aufs)分支?

是否可以將分支路徑從 stdin 提供給 mount (或 mount_unionfs)命令,而不是將它們作為參數或從檔案提供?

cat ~/dirs_with_photos.txt | mount -t unionfs

我不想使用/etc/fstab,因為理想情況下我想動態自動產生這些 txt 文件,例如使用 cron 作業:

@weekly  find $HOME -type d -iname "*photos*" > ~/dirs_with_photos.txt

答案1

將輸入轉換為所需的語法並將其拼接到命令列中命令替換

dirs_with_photos="$(<~/dirs_with_photos.txt tr '\n' :)"
if [ -n "$dirs_with_photos" ]; then
  unionfs-fuse "${dirs_with_photos%:}" /photos
fi

mount_unionfs您需要為每個目錄發出一個掛載命令。您可以使用圍繞read內建循環

while IFS= read -r dir; do
  mount_unionfs "$dir" /photos
done <~/dirs_with_photos.txt

相關內容