I would like to do the following:

  1. Open a terminal.
  2. Change to the directory where target script resides.
  3. Open the text file which provides the input to the target script. Hold/wait until the user has saved and closed the text file.
  4. Execute the target script.

I wrote the following script to do the above:

echo "hello"
gnome-terminal -x bash -c "cd ~/Scripts;pwd;gedit input.txt;python test.py;exec $SHELL"
echo "good bye"

The above gives me the following output:

user4@user-pc-4:~/Desktop$ ./DAT_run.sh
good bye

And on the new gnome-terminal opened, I see the following message:

From python script
From python script
From python script
From python script
From python script

The above means it has executed the python code and my requirements 1,2 and 4 have been met (not the 3rd). I'm unable to hold the gedit window until it has been saved and closed.

What I'm wondering is - why is the gedit command being treated as a background process when I have not indicated any such thing by writing & at the end of the statement? How can I make sure that my gedit is running as a foreground process and requires the user to take control?

What could be going wrong here? I am new to shell scripting and feel like I could very well be missing something here. How can I achieve all my above requirements?

  • gedit doesn't have a synchronous mode, you'll have to use another editor. – Michael Homer Apr 6 '17 at 7:28
  • @MichaelHomer, Could you suggest another editor in that case? – skrowten_hermit Apr 6 '17 at 7:35
  • Try nano instead. It should run in the opened terminal. – Mioriin Apr 6 '17 at 10:03
  • Are you looking at expect command? – Giacomo Catenazzi Apr 6 '17 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.