How to create Shell Script on Debian 12

To Create Shell Script On Debian 12

Introduction:

The shell script is a text file with the execution bit set and contains the commands in the following format. The first line specifies the shell interpreter which reads and executes this file contents. Reading shell scripts is the best way to understand how a Unix-like system works.

Creation Steps:

Step 1: Check the OS version by using following command.

root@linuxhelp:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL=https://bugs.debian.org/

Step 2: Create a file by using following command.

root@linuxhelp:~# touch script

Step 3: Edit the file for Create Script by using following command.

root@linuxhelp:~# vim script
#!/bin/bash
mkdir /root/directory
echo "directory created"
touch /root/directory/scriptfile
echo "script file created inside the directory"
chmod +x /root/directory/scriptfile
echo "script file executable permission created"

Step 4: Make executable permission to script file by using following command.

root@linuxhelp:~# chmod +x script 

Step 5: Check the Script file permission by using following command.

root@linuxhelp:~# ls -la
total 27604
drwx------  7 root root     4096 Sep 16 01:56 .
drwxr-xr-x 19 root root     4096 Sep 12 00:28 ..
drwxrwxr-x 32 root root     4096 Sep 12 02:14 asterisk-20.4.0
-rw-r--r--  1 root root 28187580 Jul 20 18:35 asterisk-20-current.tar.gz
-rw-------  1 root root      954 Sep 12 03:59 .asterisk_history
-rw-------  1 root root        3 Sep 12 00:55 .bash_history
-rw-r--r--  1 root root      571 Apr 11  2021 .bashrc

drwx------  2 root root     4096 Sep 12 00:35 .cache
-rw-------  1 root root       20 Sep 12 02:17 .lesshst
-rw-r--r--  1 root root      161 Jul  9  2019 .profile
-rwxr-xr-x  1 root root      226 Sep 16 01:56 script
drwx------  2 root root     4096 Sep 12 00:17 .ssh
drwxr-xr-x  3 root root     4096 Sep 12 00:42 .subversion
drwxr-xr-x  2 root root     4096 Sep 12 03:29 .vim
-rw-------  1 root root    16443 Sep 16 01:56 .viminfo
-rw-r--r--  1 root root      180 Sep 12 00:45 .wget-hsts

Step 6: Run the Script file by using following command.

root@linuxhelp:~# ./script
directory created
script file created inside the directory
script file executable permission created

Step 7: Check the output of the script by using following commands.

root@linuxhelp:~# ls -la
total 27608
drwx------  8 root root     4096 Sep 16 01:57 .
drwxr-xr-x 19 root root     4096 Sep 12 00:28 ..
drwxrwxr-x 32 root root     4096 Sep 12 02:14 asterisk-20.4.0
-rw-r--r--  1 root root 28187580 Jul 20 18:35 asterisk-20-current.tar.gz
-rw-------  1 root root      954 Sep 12 03:59 .asterisk_history
-rw-------  1 root root        3 Sep 12 00:55 .bash_history
-rw-r--r--  1 root root      571 Apr 11  2021 .bashrc
drwx------  2 root root     4096 Sep 12 00:35 .cache
drwxr-xr-x  2 root root     4096 Sep 16 01:57 directory
-rw-------  1 root root       20 Sep 12 02:17 .lesshst
-rw-r--r--  1 root root      161 Jul  9  2019 .profile
-rwxr-xr-x  1 root root      226 Sep 16 01:56 script
drwx------  2 root root     4096 Sep 12 00:17 .ssh
drwxr-xr-x  3 root root     4096 Sep 12 00:42 .subversion
drwxr-xr-x  2 root root     4096 Sep 12 03:29 .vim
-rw-------  1 root root    16443 Sep 16 01:56 .viminfo
-rw-r--r--  1 root root      180 Sep 12 00:45 .wget-hsts

root@linuxhelp:~# cd directory

root@linuxhelp:~/directory# ls -la
total 8
drwxr-xr-x 2 root root 4096 Sep 16 01:57 .
drwx------ 8 root root 4096 Sep 16 01:57 ..
-rwxr-xr-x 1 root root    0 Sep 16 01:57 scriptfile

Conclusion:

We have reached the end of this article. In this guide, we have walked you through the steps required to Create Shell Script on Debian 12. Your feedback is much welcome.

FAQ
Q
5. How can you connect to a database server?
A
To connect to a database server from Linux, use the isql utility that comes with the open client driver. Here is how:
isql –S serverName –U username –P password
Q
4. What are the four stages of the Linux Process?
A
The four stages include:
• Waiting- The Linux process is waiting for the resource
• Running- The Linux process is currently running
• Stopped- The Linux process has been stopped after successful execution
• Zombie- The Linux process is still active in the process table, but it has stopped.
Q
3. Name commonly used shells on a typical Linux system.
A
There are mainly two kinds of Linux shells- C-shell and Bourne shell. Their derivatives are as follows:
• C-shell: TENEX C-Shell, Z-Shell
• Bourne shell: Korn Shell, POSIX Shell, Bourne-Again Shell
Q
2. What do you understand by a shell?
A
Shell is a command-line interpreter that translates user-entered commands into kernel-understandable language. The shell interprets the command typed in at the terminal and calls the required program.
Q
1. What is a superblock in shell scripting?
A
A superblock is a program containing specific file systems' records. The characteristics available in the block are size, counts of filled and empty blocks, usage information, size of block groups, and location and size of inode tables.