Shell Scripting is an Open-Source Operating System.
What is Shell Scripting?
In Linux, shells like bash and korn support programming construct which are saved as scripts.These scripts become shell commands and hence many Linux commands are a script. A System Administrator should have a little knowledge about scripting to understand how their servers and applications are started, upgraded, maintained or removed and to understand how a user environment is built.
How to determine shell
You can get the name of your shell prompt, with the following command:
- Echo $SHELL
The $ sign stands for a shell variable, echo will return the text whatever you typed in.
Shell Scripting She – bang
The sign #! Is called she-bang and is written at top of the script. It passes instruction to program /bin/sh.
To run your script in a certain shell (shell should be supported by your system), start your script with #! Followed by the shell name.
Shell Scripting Comments
Any line starting with a hash (#) becomes a comment. The comment means, that line will not take part in script execution.
Shell Scripting Variables
Scripts can contain variables inside the script.
As scripts run in their own shell, hence variables do not survive the end of the script.
Shell Scripting Sourcing a file
A file is sourced in two ways. One is either writing as source <fileName> or other is writing as. ./<fileName> in the command line. When a file is sourced, the code lines are executed as if they were printed on the command line.
The difference between sourcing and executing a script is that, while executing a script it runs in a new shell whereas while sourcing a script, a file will be read and executed script run in the same shell.
In sourcing, script content is displayed in the same shell but while executing script run in a different shell.
Troubleshooting a shell script
There is one more way other than script execution to run a script in a different shell. Type bash with the name of the script as a parameter.
Syntax : bash <fileName>
Shell Scripting Prevent Setuid root spoofing
Spoofing is a technique through which a user tries to grant unauthorized access on a system be pretending to be the root user. This is called setuid root spoofing. To prevent from spoofing and you can add — then after #!/bin/bash. It is disabled further option processing so that shell will not accept any options.