Day-9: Started my day with completing 5 exercises out of 35 of Unix Badge on pentesterlab! After that did some research on Bash scripting, follow my notes below to know more!
- Okay so, BASH stands for Bourne-Again SHell. what it does is that it takes in commands from the user and performs actions using operating system services. It is basically a shell interpreter!
- A Bash script is a plain text file which contains a series of commands.
- For example, the
lscommand lists the files and folders in a directory. Bash is the improved version of Sh (Bourne Shell).
- Bash Scripting is used for:
- Managing complexities and for automating recurrent tasks.
- The first line should be "shebang" - (#!). Starts with hash character (#) and a bang character (!) and it declares the interpreter for the script.
#!/bin/bash- This line indicates that we are using bash interpreter!
- Adding Commands: The command “echo” prints out its arguments to standard output. “$@” is the variable name for all arguments passed in.
- File Permissions: First save the file in your current directory with the extension of ".sh" (The “.sh” extension is conventional for shell scripts.) and then give permission with the following command! The “chmod” command edits the permissions for a file, and “+x” indicates that we want to add the permission to execute for all users.
chmod +x hello.sh
PS: You can use any file editor like nano, vim, etc. Here I used
Got doubts? Contact me on Twitter.
Feedbacks are welcomed, do comment it down below! :)