O'Reilly logo

Mastering Bash by Giorgio Zarrelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The dot character (.)

The dot command is a shell builtin, and it has the same function of the source; when executed into the shell, it executes a file. And if it is used inside a script, it loads the referenced file content:

zarrelli:~$ comment.shbash: comment.sh: command not foundzarrelli:~$ . comment.sh* 1 2 3 comment.sh menu.sh test.txt# I am a comment but you can see me

As we can see from this example, the first try was not successful because comment.sh is not in the search path; but the second time, we were successful since the dot command executed the script. Now, let's see how to include some code from an external file into a script. Let's start writing the external file that we will source from the following code:

zarrelli:~$ cat ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required