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.
Comments ( 0 )
No comments available