When attempting to change directory with _!cd_ command, it didn't seem to work well. A notebook to reproduce this issue can be found at https://colab.research.google.com/notebook#fileId=1C9x_lQreBVBUvIBOtJD0NHecD6UAHYv4
For your convenience, the screenshots are also attached.


tl;dr: this is a known gotcha.
Commands prefixed with ! are run in a new subshell -- so you're starting a new shell, changing directories, and ... letting the shell process quit. (You can do things like !cd /tmp && ls to run a command in another directory.
By default, IPython enables automagics, which lets you skip the leading %.
This means that the cd command is shorthand for %cd (docs), which changes the directory of the python process itself, not a child subprocess. That's why these changes stick.
I'm closing as WAI, but feel free to ask if that isn't clear.
@craigcitro Thanks very much. I just knew that IPython can work as a shell, because I only used Jupyter notebook in the Windows environment and never tried shell commands before. I thought _!cmd_ was a feature of Colab.
Anyway, got it. Thank you.
@craigcitro @ShuhuaGao
can someone please clarify what to put instead of !cd foo/bar ?
Thanks, I should have reported back that I tried that and it worked :)
On Sun, Jun 16, 2019, 21:23 Maxim Ziatdinov notifications@github.com
wrote:
What about %cd foo/bar ?
On Sun, Jun 16, 2019, 5:43 AM Nobutaka notifications@github.com wrote:
@craigcitro https://github.com/craigcitro @ShuhuaGao
https://github.com/ShuhuaGaocan someone please clarify what to put instead of !cd foo/bar ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<
https://github.com/googlecolab/colabtools/issues/40?email_source=notifications&email_token=AIFIU22OXNYHYYI6KL6PDCTP2YDKNA5CNFSM4EOHO7T2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXZJI3A#issuecomment-502436972
,
or mute the thread
<
https://github.com/notifications/unsubscribe-auth/AIFIU227Y7OYMIEZZWXHF5LP2YDKNANCNFSM4EOHO7TQ.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/googlecolab/colabtools/issues/40?email_source=notifications&email_token=AGAFZKMQC3DB4IKDA7UY5XTP2Y5EVA5CNFSM4EOHO7T2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXZM6KY#issuecomment-502452011,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGAFZKL4MFVDDPUGGEJ65ULP2Y5EVANCNFSM4EOHO7TQ
.
@craigcitro @ShuhuaGao
can someone please clarify what to put instead of
!cd foo/bar?
%cd foo/bar
Can somebody please tell me a solution of the code in "How to reproduce" section of issue #1094 (It's closed)
@Monster-Gaming-Studios see the last comment on this issue above yours: instead of !cd you want %cd. The reason is explained earlier in this issue.
Most helpful comment
tl;dr: this is a known gotcha.
Commands prefixed with
!are run in a new subshell -- so you're starting a new shell, changing directories, and ... letting the shell process quit. (You can do things like!cd /tmp && lsto run a command in another directory.By default, IPython enables automagics, which lets you skip the leading
%.This means that the
cdcommand is shorthand for%cd(docs), which changes the directory of the python process itself, not a child subprocess. That's why these changes stick.I'm closing as WAI, but feel free to ask if that isn't clear.