找到了带有test和$ status的解决方案
# Get status vagrant status --machine-readable | grep state,running # Check status if test $status -eq 0 # Vagrant is running vagrant halt # Send notification notify-send "Vagrant is halted." else # Vagrant is not running vagrant up # Send notification notify-send "Vagrant is up." end