我可以使用该case
语句来处理参数吗?所以,使用 -restart 我想执行“-umount”和“-mount”
#!/bin/bash
case "$1" in
-mount
mount /ip/share1 /local/share1
;;
-umount
umount /ip/share1
;;
-restart
# echo TODO
;;
*)
[...]
esac
Run Code Online (Sandbox Code Playgroud)
Dop*_*oti 10
在我看来,这应该有效,除了缺少)
s的语法狡辩。我对此进行了测试,它的行为正确..
#/bin/bash
case "$1" in
"-mount")
mount /path/to/device /path/to/mountpoint
;;
"-unmount")
umount /path/to/mountpoint
;;
"-remount")
"$0" -unmount
"$0" -mount
;;
*)
echo "You have failed to specify what to do correctly."
exit 1
;;
esac
Run Code Online (Sandbox Code Playgroud)