Are there any differences between commands that you type into the terminal and commands you include in a script?
Your terminal runs a shell (most probably
bash), which is the one asking for your commands and runs them.
Besides of this interactive mode you can also use your shell to run commands from a file. To execute the commands in your file you can either call the shell directly like
bash script or you can start your file with a "shebang"
#!/bin/bash and make it executable (
chmod +x script). Then you can treat the script like a binary and execute it for example as
./script or put it at a place where you shell is looking for it. (
Most probably both your interactive shell and the shell used to run is
From the perspective of a "first day learning linux" bash works exactly the same in both modes. - Much later you might stumble about slight differences. If you really want to know about in detail I would suggest reading
man bash and search for places mentioning "interactive". (You can search a man page, by pressing
One important thing to note is that the script is run as a new process. This especially means that variables set in the script are not visible in the calling shell.
$ export a=1 $ echo $a 1 $ bash -c 'echo $a;a=2;echo $a' # change the value in a script 1 2 $ echo $a # value not changed here 1 $
Without the export
a is not even visible to the inner script.
In general, the answer would be "no", commands in shell are the same in scripts, in syntax and semantics.
But there is a bunch of small nuances related to configuration of environment (what variables are used and to what they are set).
the interactive shell of choice for Linux is bash, but scripting often uses other interpreters (
sh, which is a predecessor of
ksh, which is on par with bash), so you have to take into account what shell is used (the current shell s name is traditionally held in variable
SHELL, try typing
there may be differences in configuration of the same interpreter for interactive session and for script execution.
No. A script is a list of commands you can type in the terminal.
You can paste the totality of a script in the terminal, and the result will be the same as running it.
Inversely, you can "save" your terminal commands inside of a file and turn it into a reusable script and share it with your family and friends.