How to check if a file is open in editor?

OK. I don't have leafpad or gedit on my system. When testing with vi (note that in post #10, the O.P. said that gedit and vi were used interchangeably), by running the command line:

vi somefile& PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID

I immediately get:

vi somefile& PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID
[1]	83379

and about 10 seconds later I get:

[1] + Stopped (SIGTTOU)        vi somefile& PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID

noting that vi is stopped; not terminated. And about 10 seconds later, the fg $PID brings vi somefile into the foreground so I can edit somefile . When I quit vi , I then get a new shell prompt for another command.

When I attempted this, with identical code except I use gedit rather than vi it returned:

gedit Repository.sh & PID=$!; sleep 10; jobs $PID; sleep 10; fg $PID
[1] 24318
[1]+  Done                    gedit Repository.sh
bash: jobs: 24318: no such job
bash: fg: 24318: no such job

Saying that there is no such job? What do these errors mean?

It means that gedit terminated in the 10 seconds before the jobs command started running. Under normal circumstances, it would also mean that you issued another command in those 10 seconds to reap the exit status of gedit (such as wait $PID or wait without an operand) before the jobs command started running.

Does gedit start an editing session in your current window (like vi does) or does it start an editor in a new window? If it starts it in a new window, do you get a new shell prompt in your shell window immediately after typing in the command:

gedit Repository.sh

or do you not see a new shell prompt until that editing window closes?

What operating system are you using?

1 Like

When I input

gedit Repository.sh

into the terminal it will open the text editor in another window, unless I have already got a file open in gedit by using

Applications > Text Editor

When there is not already a file open I must close that file in order to use the terminal again. However if there is a file open I can continue to use the terminal immediately after typing

gedit Repository.sh

I am using Ubuntu 17.04.

---------- Post updated at 02:25 AM ---------- Previous update was at 02:14 AM ----------

Just to clarify - I'm not typing "Applications > Text Editor" into the terminal. That's just the 'clicks' I make to open it.

---------- Post updated at 10:11 AM ---------- Previous update was at 02:25 AM ----------

Hi all! Today I decided I would use the 'Bash in Windows' BETA and I've moved all my files onto that and for whatever reason all the previous examples that rely on the PID have worked! Currently I am using:

DISPLAY=:0 gedit "$1" & PID="$!"
			while : 
			do
			sleep 1
				if [ -x /proc/$PID ]; then
					clear
					tput cup 2 5 ; echo -e "${RED}           Can not update log until editor is closed!           ${NC}"
					tput cup 3 5 ; echo -e "${boldon}Please finish editing your file and close gedit.${boldoff}"
				else
					clear
					updateLog
				fi
			done

And it works perfectly! Thank you everyone that helped!