Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1
[3] 1437

The numbers echoed back show a number ( 3 in this example), which is a job
number, or reference number for a shell process, and a process ID number, or
PID ( 1437 in this example). You can kill the xterm window session by
using the shell’s built-in kill command, along with the job number, like
this:


Click here to view code image
matthew@seymour:~$ kill %3


Or you can kill the process by using the kill command, along with the PID,
as follows:


Click here to view code image
matthew@seymour:~$ kill 1437


You can use background processing in shell scripts to start commands that
take a long time, such as backups:


Click here to view code image
matthew@seymour:~$ tar -czf /backup/home.tgz /home &


Writing and Executing a Shell Script


Why should you write and use shell scripts? Shell scripts can save you time
and typing, especially if you routinely use the same command lines multiple
times every day. Although you could also use the history function (by
pressing the up or down arrow keys while using bash or using the history
command), a shell script can add flexibility with command-line argument
substitution and built-in help.


Although a shell script doesn’t execute faster than a program written in a
computer language such as C, a shell program can be smaller in size than a
compiled program. The shell program does not require any additional library
support other than the shell or, if used, existing commands installed on your
system. The process of creating and testing shell scripts is also generally
simpler and faster than the development process for equivalent C language
commands.


NOTE
Hundreds of commands included with Ubuntu are actually shell scripts, and
many other good shell script examples are available over the Internet; a
quick search yields numerous links to online tutorials and scripting guides
from fellow Linux users and developers. For example, the startx
Free download pdf