Learn Bash Scripting With Me πŸš€ - Day 1

B

Babs

Guest

LearnBashScriptingWithMe πŸš€

Day 1 – Introduction, Shebang & File Permissions​


Bash scripting is the process of creating a file that contains a sequence of commands and then running that file as a script.

A shell in Kali Linux is a command-line interpreter that provides an interface for the user to interact with the operating system. It allows users to execute commands, scripts, and programs to manage the system, navigate the file system, and perform various administrative tasks.

πŸ‘‰ We start by creating a file using the β€œsh” extension as this is used to denote that we are creating a shell script, e.g test.sh

πŸ‘‰ After that the next thing we need to do is to define the kind of interpreter we are going to be using and for this, the interpreter is BASH and we denote that using


Code:
#!/bin/bash

πŸ‘‰ Inside the script, we can use the echo command to display output. For example, printing β€œHello World!”


Code:
echo "Hello World!"



πŸ‘‰ Now we can now save and run the script by using the command β€œ./(filename)”
e.g:


Code:
./test.sh

Note that the command "./" is telling the shell to use the interpreter defined in the file we want to run which was what was defined first when we wrote "#!/bin/bash" in the file

But noticeβ€”you might get a β€œpermission denied” error. That’s because the file isn’t yet executable.



πŸ‘‰ To fix this, grant execution permission with:


Code:
chmod +x test.sh

Now, when you run ./test.sh, the script executes successfully πŸŽ‰



Bash #scripting​


Continue reading...
 


Join 𝕋𝕄𝕋 on Telegram
Channel PREVIEW:
Back
Top