Skip to content

Instantly share code, notes, and snippets.

@TonyWhite
Created January 14, 2022 12:00
Show Gist options
  • Select an option

  • Save TonyWhite/9365df5b337ef449df59408da02badbe to your computer and use it in GitHub Desktop.

Select an option

Save TonyWhite/9365df5b337ef449df59408da02badbe to your computer and use it in GitHub Desktop.
Detects whether the bash script is started from the GUI or the shell
#!/bin/bash
# Start from GUI?
GUI=false
if [[ $(readlink -f /proc/$(ps -o ppid:1= -p $$)/exe) != $(readlink -f "$SHELL") ]]; then
GUI=true
fi
# Show message
if [[ $GUI == true ]]; then
zenity --info --ellipsize --text="Script started from GUI"
else
echo "Script started from shell"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment