Question

I've written a simple bash script that prompts for a file or directory path and opens it with exo-open, I've then assigned the script to a keyboard shortcut so that I can CTRL+SHIFT+ALT+O to open anything at anytime via a terminal prompt:

The keyboard binding

And the script:

#!/bin/bash

# CD to the home folder (not sure if this is needed, no harm either way)
cd ~/

# Request the filepath
echo -e "\e[1;31mEnter a file or directory:\e[00m"
read -e -i "~/" filename

# Convert ~/ to /home/username/
filename=`eval "echo $filename"`
echo -e "opening\e[1;32m" $filename "\e[00m"

# Open the file
exo-open "$filename"

echo "press enter to exit"
read enter

My problem is that the spawned program is linked to the terminal, when the terminal closes it takes the program with it - as a simple workaround I have another user prompt at the end to stop the terminal from closing; does anyone know how I could allow the terminal to close but keep the resulting program open?

Some ideas I've had / tried:

  • run disown $! after exo-open (didn't work)
  • use nohup (didn't work)
  • Run exo-open from the PPID (no idea how to do this)

At my wits end :-(

Was it helpful?

Solution

I had this answered by Xfce forum member ToC

http://forum.xfce.org/viewtopic.php?pid=25670

Turns out you can use setsid like so:

#!/bin/bash

# CD to the home folder (not sure if this is needed, no harm either way)
cd ~/

# Request the filepath
echo -e "\e[1;31mEnter a file or directory:\e[00m"
read -e -i "~/" filename

# Convert ~/ to /home/username/
filename=`eval "echo $filename"`
echo -e "opening\e[1;32m" $filename "\e[00m"

# Open the file
setsid exo-open "$filename"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top