3 Basic Commands and Simple Shell Scripts Once you have your first Red Hat Enterprise Linux rhel



Download 1.85 Mb.
View original pdf
Page26/67
Date26.02.2024
Size1.85 Mb.
#63678
1   ...   22   23   24   25   26   27   28   29   ...   67
Pablo Iranzo Gómez, Pedro Ibáñez Requena, Miguel Pérez Colino, Scott McCarty - Red Hat Enterprise Linux 9 Administration-Packt Publishing (2022) -chap 3 82 - 180
Creating basic shell scripts
As a system administrator (or sysadmin, there will betimes when you want to run a series of commands more than once. You can do this manually by running each command every time. However, there is a more efficient way to do so – by creating ab shell script
.
A shell script is nothing more than a text file with a list of commands to be run and a reference to the shell that will interpret it.
In this book, we will not cover how to use ab text editor
; however, we will provide three recommendations for text editors in Linux that could be of help Nano: This is probably the easiest text editor to use for beginners. Lean, simple, and straightforward, you may want to start by installing it and giving it a try vi orb vimb: vi is the default text editor available in RHEL, even included in the minimal install and in many Linux distributions. Even if you are not going to use it everyday, it’s good to familiarize yourselves with the basics of it as it will be present in almost any Linux system you will use. vim stands for vi-improved.
Emacs: This is probably the most advanced and complex text editor ever. It can do everything and beyond, including reading emails or helping with a bit of psychoanalysis via Emacs Doctor.
We can create our first shell script by editing anew file called hello.sh with the following line as its content:
echo 'hello world!''

Creating basic shell scripts
93
Then, we can run it by using the bash command interpreter with the following line:
[root@rhel-instance
]# bash hello.sh

hello world!
There is a different way to do this where we do not need to type bash. We can add an initial line referencing the interpreter, so the file content of hello.sh looks as follows:
#!/bin/bash echo 'hello world!''
Now, we change the permissions to make it executable:
[root@rhel-instance
]# ls -l hello.sh


Download 1.85 Mb.

Share with your friends:
1   ...   22   23   24   25   26   27   28   29   ...   67




The database is protected by copyright ©ininet.org 2024
send message

    Main page