In this tutorial we will see what is the source builtin command.
We will set the prompt of our tcsh as example.
Let's go.
We can change the prompt with a script. But without modifying the .tcshrc file. It means that each new terminal you will open will be with the default shell config, in this case .tcshrc.
Let's make a classic script by creating a new file named tcshScript.
Let's open it and write this inside:
#!/bin/tcsh set prompt = 'The time is %T'
The first line is called shebang. It is a comment because it starts by the sharp character (#). But with the exclamation point (!) just after, it becomes a clue for the shell to execute it with the correct program and the correct PATH /bin/tcsh.
The second line will set the prompt with the sentence and the time.
Let's now execute it.
Let's return to the terminal and type this:
$ chmod +x tcshScript
This will change the chmod of the file by setting the appropriate rights. In this case, it is the same as the 755 rights.
Now the Shell can execute this file as a program.
Let's do it:
$ ./tcshScript
Well, it does nothing!
Why?
Because when a script is executed like that:
$ ./myScript
it is in a different shell (process) and once completed, all what this new shell done is lost. The main process appears again without any change of course.
So, how to resolve this problem?
With the source builtin command!
Let's try with source this time:
$ source tcshScript
Yes, it works!
Why?
Because this time the script is executed in the current shell and so all changes will be applied. But only for this shell. Try to open a new one and all changes will be gone.
Add new comment