! [ -e /content ] && pip install -Uqq fastbook

Good morning;
I am getting started in deep learning, through this wonderful resource that is the Fastai MOOC. As I am totally a beginner, there are things that are surely very basic, but I still do not understand them. In the notebook in lesson 2, in the first cell (before importing the code, the first line of the code is:
``` ! [ -e /content ] && pip install -Uqq fastbook.````
Is it a directive? What exactly does it mean?
Thank you

2 Likes

“!” → tells Jupyter notebook to pass the remaining line to bash shell

[ -e /content ] → is the command in bash to check if a file or directory exists and returns true or false. So, here we’re checking if a directory called content exists at the path /content (/ is the root directory and content would be right under it if it exists)

&& → it means “If the last command returned True, run the next command.” So we just checked whether a directory /content exists or not. If it exists we’ll move on to running the command that comes after “&&” since the output of [ -e /content] would be “true”

pip install -Uqq fastbook → install fastbook package and Upgraded it (-U) if it already exists. -qq means be very very quiet?

8 Likes

I understood, Thank you!!!

1 Like

Very nice explanation!
I have a follow up question.
Why does it check for existence of the ‘/content’ dir/file in the root directory? I mean why is it a prerequisite for installing or upgrading fastbook? Is it related to a certain system? On Mac or linux there no such dirs/files by default in the root directory.

As far as I understand the directory “/content” only exists for Google Colab. The reason why it is needed there is because in Colab fastbook is not up-to-date. So, I think, this line of code won’t do anything, unless you’re running your jupyter notebook on Colab. You can see this part of the Live Coding 2 where Jeremy explains it.

1 Like

Thank you! That explains it. Also, thank you for the live coding link. It also shows that on the other platforms Jeremy prefers to use mamba for installation

1 Like