Mastering Bash

Author: Giorgio Zarrelli  

Publisher: Packt Publishing‎

Publication year: 2017

E-ISBN: 9781784391980

P-ISBN(Paperback): 9781784396879

Subject: TP316 操作系统

Keyword: 操作系统

Language: ENG

Access to resources Favorite

Disclaimer: Any content in publications that violate the sovereignty, the constitution or regulations of the PRC is not accepted or approved by CNPIEC.

Mastering Bash

Chapter

Chapter 1: Let's Start Programming

I/O redirection

Messing around with stdin, stdout, and stderr

Time for the interpreter: the sha-bang

Calling your script

Something went wrong, let's trace it

Variables

Assigning a variable

Keep the variable name safe

Variables with limited scope

Environment variables

Variable expansion

Pattern matching against variables

Special variables

Summary

Chapter 2: Operators

Arithmetic operators

The + operator

The - operator

The * operator

The / operator

The % operator

The ** operator

Assignment operators

The += operator

The -= operator

The *= operator

The /= operator

The %= operator

The ++ or -- operators

Bitwise operators

Left shift (<<)

Right shift (>>)

Bitwise AND

Bitwise OR (|)

Bitwise XOR (^)

Bitwise NOT (~)

Logical operators

Logical NOT (!)

Logical AND

Logical OR (||)

Comma operator (,)

Operators evaluation order and precedence in decreasing relevance

Exit codes

Exiting a script

Summary

Chapter 3: Testing

What if...else

Test command recap

Testing files

Testing integers

Testing strings

More on tests

Summary

Chapter 4: Quoting and Escaping

Special characters

The hash character (#)

The semicolon character (;)

The double semicolon character (;;)

The case terminator (;;&) and (;

The dot character (.)

The double quotes (

The single quotes ('...')

The comma character (,)

The ,, and , () case modificators

The ^^ and ^ () case modificators

The backslash (\)

The forward slash (/)

'...'

The colon character (:)

The exclamation (!)

Keywords

The asterisk (*)

The double asterisk (**)

Test operators (?)

The substitution ($)

The parameter substitution (${})

The quoted string expansion ($'...')

The positional parameters ($* and $

The exit status ($?)

The process ID ($$)

 Grouping the command (command1 ; command2 ; commandn)

Braces ({})

The full path ({} \;)

Expression ([])

Expression ([[]])

The array index ([])

Characters range ([])

Integer expansion ($[…])

Integer expansion (((..)))

DEMO

The here document (<<)

The here string (<<<)

The ASCII comparison operators (<) and (>)

Delimiters (\< and \>)

The pipe character (|)

The force redirection (>|)

The logical OR (||)

DEMO

Logical AND

The dash character (-)

The double dash (--)

Operator = 

Operator +

The modulo operator (%)

Operator ~

Operator ~+

Operator ~-

Operator ~=

Operator ^

The control characters (^ and ^^) 

Quoting and escaping

The backslash (\)

Double quotes (

Single quotes (')

Summary

Chapter 5: Menus, Arrays, and Functions

The case statement

Arrays

Functions

Summary

Chapter 6: Iterations

The for loop

Let's do something while, until…

Exiting the loop with break and continue

Time to give our client a menu

CLI, passing the arguments to the command line

Summary

Chapter 7: Plug into the Real World

What is Nagios?

Active and passive checks

Active checks

Passive checks

Returning code and thresholds

Command and service definitions

Our first Nagios plugin

Summary

Chapter 8: We Want to Chat

The Slack messaging service

Slack WebHooks

What is a JSON?

Do you like cURLing?

Formatting our messages

Message attachments

Our wee chatty script for Slack

Summary

Chapter 9: Subshells, Signals, and Job Controls

What is a subshell?

Background processes

Signals

Job controls

Subshells and parallel processing

Summary

Chapter 10: Lets Make a Process Chat

Pipes

Redirection to a file

The command substitution

The process substitution

Environment variables

Coprocesses

/dev/tcp and /dev/udp

Netcat

Summary

Chapter 11: Living as a Daemon

What is a daemon?

DEMO

nohup

disown

Double fork and setsid

Becoming a daemon

Trapping a daemon

Going dark with the daemon

Summary

Chapter 12: Remote Connections over SSH

What is SSH?

Configuration files

The sshd_config file

ssh_config

Passwordless connections

Configuring the server

Preparing the remote account

Configuring the client

Proxies and tunnels

Summary

Chapter 13: Its Time for a Timer

One shot at it

The cron scheduler

cron

Summary

Chapter 14: Time for Safety

The restricted shell

Restricted shells for OpenSSH

Restricted sftp sessions with OpenSSH

Summary

Index

The users who browse this book also browse