DEV Community

Cover image for Learn Bash Scripting With Me πŸš€ - Day 1
Babs
Babs

Posted on

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

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

#!/bin/bash
Enter fullscreen mode Exit fullscreen mode

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

echo "Hello World!"
Enter fullscreen mode Exit fullscreen mode

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

./test.sh
Enter fullscreen mode Exit fullscreen mode

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:

chmod +x test.sh
Enter fullscreen mode Exit fullscreen mode

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

Bash #scripting

Top comments (0)