Bash is the most common shell
We can find the shell being used by using the following command: `echo $SHELL`.
We can find a list of available shells by checking in `/etc/shells`.
To change shells you can type the name of the shell in the terminal and hit enter.
To permanently change your default shell you can use the following command: `chsh -s /usr/bin/zsh`, with the provided example the new shell would be ZSH instead of Bash.
## Creating a Script:
Every script should begin with a shebang. The Shebang is a combination of characters that are added at the beginning of a script, starting with `#!` followed by the name of the interpreter to use while executing the script. For a script being ran by bash we would use the following - `#!/bin/bash`.
Variables: Store values such as URL, file path, and more.
Example:
```
#Define the interpreter
#!/bin/bash
echo "Hello, who are you?"
read name
echo "Hi there, $name"
```
The provided example uses bash as the interpreter, it uses echo to display the message "Hello, who are you?", and then it uses `read` to take user input for the variable `name`. Then the script will echo the final message with the users input for the variable `name`.
When running the newly created script, we must first change its permissions to allow it to be executed by using `chmod +x` on the file.
To run the script after adding execution permissions, we do the following: `./script.sh`. The reason we use `./` instead of typing just the script name is to tell the interpreter to launch the script in the current directory. Otherwise, the shell will search the script in the PATH environment variable (that contains all the directories except the current one) and it will not find the script file and result in an error.
To add comments to the script for better readability use the `#` symbol followed a space and then by the comment.
### Loops:
Example code with loop:
```
#!/bin/bash
for i in {1..10};
do
echo $i
done
```
Explanation: The first line has the variable `i` which will iterate through 1 to 10, executing the code every time. The `do` in the second line indicates the start of the loop and `done` indicates the end. The code will apply the variable `i` for each number in the range between 1 to 10. The last portion of the code `echo $i` will display the variables value for every iteration.
#### Conditional Statements:
Allows for only specific code to execute when certain conditions are met, otherwise a different code snippet may be executed. Say you want to have a script that shows users a special file but you only want specific users to see the special file. You input a conditional statement that checks, lets say the users name, and then if the name provided matches one of the users who should see the special file then it will be displayed, otherwise nothing is shown.
Example script:
```
#!/bin/bash
echo "Enter your name"
read name
if [ "$name" = "Dumphuk" ]; then
echo "Welcome Dumphuk, the secret: depths"
else
echo "Who tf are you!? Yea sorry no access for u, kik roks."
fi
```
The script will take the users input and store it in the variable `name`. It will then check to see if the name matches that of the intended user, if so it will display the secret, if not then well, kik roks.
Final:
```
#Define the interpreter
#!/bin/bash
#Define the variables
username=""
companyname=""
pin=""
#Define the loop
for i in {1..3}; do
#Define the conditional statements
if [ "$i" -eq 1 ]; then
echo "enter username:"
read username
elif [ "$i" -eq 2 ]; then
echo "enter company name:"
read companyname
else
echo "enter your PIN:"
read pin
fi
done
#checking if the user entered the correct details
if [ "$username" = "Dumphuk" ] && [ "$companyname" = "Sudo Wizards" ] && [ "$pin" = "1798" ]; then
echo "authentication success, access granted dumphuk"
else
echo "u moron, no access for u"
fi
```