Linux Essentials (010-160): A Time Compressed Resource to Passing the LPI® Linux Essentials Exam on Your First Attempt by Dion Jason
Author:Dion, Jason [Dion, Jason]
Language: eng
Format: epub
Publisher: Dion Training Solutions, LLC
Published: 2020-07-19T16:00:00+00:00
The first line begins with two characters (#!). These two characters are a special code that tells the Linux kernel that this is a script and that the rest of the line should be treated as a pathname to the program that will interpret this script. In this script, it is the path /bin/bash, which is the path to the bash shell program.
Within a shell script, the pound symbol or hash mark (#) is considered a comment character. This causes the script utility to ignore this line, but the kernel still reads it. On most Linux systems, /bin/sh is a symbolic link that points to /bin/bash, but it can also point to another shell. If a user specifies the script as using /bin/sh instead of /bin/bash, this almost certainly guarantees that any Linux system will be able to execute the script since they all have a shell program to run the script. If it is a simple bash script, the script can be run in most other shells. Unfortunately, if the script is more complex, then it will need a specific shell or else it could fail.
After writing the shell script, we must modify the text file to ensure it is now an executable file within the operating system by using the chmod command. The use of chmod will be covered in Chapter 12 (Ownership and Permissions).
As you begin to create shell scripts that are lengthier and more complex, you will want to have a good text editor program. If using a graphical desktop, KWrite and gnome’s gedit editors are excellent for creating text shell scripts. However, if working from a command line, then vi, emacs, pico, or nano can be used instead.
Using Commands in Scripts
The simplest use of a script is to run a series of commands without user intervention. Commands built into the shell and external commands can both be used in scripts. This means that other programs can also be run from within a script.
Most of the commands that a user enters in the shell prompt are external commands. All these programs are located in /bin, /usr/bin, and other directories within the filesystem. These programs, as well as internal commands, can be run by simply using their names within the script. If needed, we can also specify parameters for each of these programs in a script. For instance, consider the following script for copying a file from Downloads to Documents, launching an xterm window, and then starting up the KMail mail reader program inside the GUI:
#!/bin/bash
cp ~/Downloads/file.txt ~/Documents/file.txt
/usr/bin/xterm &
/usr/bin/kmail &
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
TCP IP by Todd Lammle(2633)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2309)
Networking A Beginner's Guide by Bruce Hallberg(1932)
The KCNA Book by Nigel Poulton(1918)
Red Hat Certified Specialist in Services Management and Automation EX358 Exam Guide by Eric McLeroy(1854)
31 Days Before Your CompTIA A+ Exams (Shanette Luellen's Library) by Benjamin Patrick Conry(1660)
MCSA Windows Server 2016 Study Guide: Exam 70-741 by William Panek(1476)
Unity Certified Programmer: Exam Guide by Philip Walker(1475)
PHP 7 Zend Certification Study Guide by Andrew Beak(1449)
Healthcare Information Security and Privacy (All-In-One) by Sean Murphy(1368)
CompTIA A+ Certification Guide (220-901 and 220-902) by Matthew Bennett(1337)
RHCSA & RHCE Red Hat Enterprise Linux 7: Training and Exam Preparation Guide (EX200 and EX300), Third Edition by Asghar Ghori(1302)
Mobile Computing Deployment and Management by Robert J. Bartz(1252)
Essential Office 2016 by Wilson Kevin(1251)
Microsoft Security, Compliance, and Identity Fundamentals Exam Ref SC-900 by Dwayne Natwick(1243)
Designing and Implementing Microsoft Azure Networking Solutions by David Okeyode(1235)
Essential Office 2016 (Computer Essentials) by Kevin Wilson(1223)
The Tao of Network Security Monitoring by Richard Bejtlich(1194)
CCNA Cisco Certified Network Associate Practice Labs and Simulations by Shwergho Smith(1144)