How do I get back to nano after hitting Ctrl-Z if I have no shell prompt (in Matlab session)
Solution 1
In the comments the author says that he or she is running the nano
command from Matlab, and that there is no prompt whatsoever after suspending it with CTRL-Z. This is probably a bug in Matlab(1) which should not allow a CTRL-Z arrive to nano if it can't cope with it...
The problem is that the shell command fg
(and bg
, and jobs
) works only with direct children of the shell. But you can continue a stopped process from another shell, although this will not guarantee that the status of the screen is correctly managed:
-
in another terminal window, find the
nano
process:% ps ugx | grep nano romano 10600 0.0 0.0 20784 1628 pts/11 T 16:52 0:00 nano prova romano 10653 0.0 0.0 18256 900 pts/11 S+ 16:53 0:00 grep nano
Notice that it is stopped (state
T
)-
Continue it with
kill -CONT 10600
...and hope it works (can mess up the terminal greatly). You can also trying a
killall -CONT nano
that way the CONT
signal is sent to all the "nano" processes (shouldn't be a problem though).
Footnotes:
(1) I tried with octave
: EDITOR=nano octave
and then edit file
in octave. Pressing CTRL-Z messes the things up quite well... so maybe it's not Matlab but a strange interaction on who receive and manage the TSTP signal.
Solution 2
If it's the only backgrounded process entering %
followed by Return should return you to nano.
That said running fg
should work too. It's a shell builtin that takes the last job and returns it to the fore. Even when you have more than one job, it should bounce you back to the newest one.
Solution 3
List your jobs
jobs
Bring a job to the foreground
fg 1
change the "1" to the job number corresponding to nano.
Related videos on Youtube
user282315
Updated on September 18, 2022Comments
-
user282315 over 1 year
I'm using nano inside a MATLAB session that is running inside a screen (-x) terminal. I accidentally hit Ctrl-Z and it immediately leaves nano, prints "Use "fg" to return to nano", but does not show a command prompt. Whatever I type appears on the screen but nothing responds. If I hit Ctrl-Z, ^Z just prints to the screen. Any ideas? Using 12.04.
-
Rmano about 10 yearsYou should have a prompt after hitting ctrl-z. I have... it seems that this is not happening in your case. How exactly do you run
nano
in the terminal? -
user282315 about 10 yearsI just realized I'm not really using 12.04. I am in fact running
nano
from inside a MATLAB session, which is (obviously) the problem (sorry about neglecting to mention that; I'd forgotten I was in MATLAB). Callingjobs
in another screen does not list any jobs to pull up.
-
-
user282315 about 10 yearsAwesome, that did it. This issue had been bothering me for a while! Logging a bug with TheMathWorks. Thanks!
-
user282315 about 10 yearsAlas, new account, no reputation to upvote (yet).
-
DonSeba over 8 yearsimo, this is the real answer, it does what the op ask's , reopen the closed (ctrl+z) Nano windows.
-
pietrovismara over 6 yearscool tricks here.
-
Arefe over 6 yearsThis help me too.
-
user2180794 over 6 yearsThis should be the right answer.
-
Maryna Klokova almost 4 yearsThis solution saved my day!
-
vulcan raven over 3 years"The correct answer is likely not the accepted one." #sad-but-true
-
Jacky Supit over 3 yearswow thank you!!! this should be the accepted answer!
-
Admin almost 2 yearsthe only thing that was missing in this answer for me is the mention that fg is actually a command for the commandline. As a noob in linux commandline this might be valuable information.
fg
worked perfectly for me though.