title: make bash script display system event dialog, then take its result and use it in an if statement
body: <p>I'm on macOS. I have a script that, after asking for confirmation using <code>read</code> in Terminal, uses <code>grep</code> to check whether /dev/disk1 is mounted, then formats that disk. That's a dangerous script, hence why asking if it's okay first is vital.</p>
  
  <p>Eventually, I would like to have this script be an executable that the user can double-click on. But rather than having the user type "y" and Return into a Terminal window, I would rather a display dialog appear with "yes" and "no" buttons, have them choose, then have the script run based on their answer. Is this possible in bash?</p>
  
  <p>I'm working in an environment in which I don't have administrative access, so while I can write an AppleScript Service to accomplish what I want to do and to integrate this elegantly into the user interface, I can't integrate that Service into the environment without the admin password (since I can't edit ~/Library/Services for the user without it). Also, I cannot download or install any new libraries, applications — anything, really — in the environment; I must only use native bash in Mac OS X.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>read -p "Are you sure you want to partition this disk? " -n 1 -r # Can I make this be a dialog box instead?
  echo 
  
  if [[ $REPLY =~ ^[Yy]$ ]] # Can this accept the result as a condition?
  then
      if grep -q 'disk1' /dev/ &amp;&amp; grep -q 'file.bin' ~/Downloads; then
          echo # redacted actual code
      else
          osascript -e 'tell app "System Events" to display dialog "The disk is not mounted."'
          exit 1
      fi
  else
      exit 1
  fi
  </code></pre>
  
  <p>Thanks very much for your help.</p>