I made a bash script which takes an input form the user:

#!/bin/bash
# mnthere - mounts virtual box share in current working directory
echo Enter the source share name:
readline NAME
sudo -- mount -t vboxsf -o rw,uid=1000,gid=1000 $NAME $0

But when I double-click it, nothing happens. It executes in background probably failing with an error. I need to configure it to show that window, how do I do that? Is that related to XFCE4 desktop environment I am using?

up vote 2 down vote accepted

If you don't want to modify the launcher, you can check at the beginning of the script whether it is being executed in a terminal. If it isn't, open a terminal and restart the script there. At the top of the script:

if [ ! -t 1 ]; then
    args=''
    for arg in "$@"; do
        args="$args \"${arg//\"/\\\"}\""
    done
    xfce4-terminal -e "$0 $args"
    exit 0
fi

Then if there is any terminal output to display to the user, add this to the bottom:

read -n1 -u1 -rp 'Press any key to close this window.'

Launch an xterm running your script instead of just running your script and add a read command for instance to stop the output and be able to read.

gnome-terminal -x your_script

  • In other words, double clicking the bash file just does never spawn the console window? – Tomáš Zato Oct 1 '15 at 9:12
  • Right, it will execute but it won't have an Xwindow container. – YoMismo Oct 1 '15 at 9:15

If you edit the launcher (right-click, select Properties, then click on the edit button), one of the options will be a check-box "Run in terminal".

Check that and your script will now run in a terminal.

  • There's no such option in my xfce. Or maybe I am just not sure what do you refer to as "launcher". – Tomáš Zato Oct 1 '15 at 11:56
  • how do you "click on it" - did you make a launcher icon on the desktop, or from within Thunar or some other file browser. If the latter, I don't think there's any way to do what i said (except right-click, Send To -> Desktop to make a desktop icon). If the former, then it's both easy and obvious. – cas Oct 1 '15 at 22:56
  • but my specific instructions were mistakenly for a panel icon. For a desktop icon, it's right-click, select Properties, and then select the Launcher tab. – cas Oct 1 '15 at 22:57
  • It's not here. Are you talking about xfce or Ubuntu? image – Tomáš Zato Oct 2 '15 at 7:28
  • xfce. v4.12.1 on debian sid, to be precise. other versions may vary. – cas Oct 2 '15 at 7:29

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.