Christopher Negus - Linux Bible

Здесь есть возможность читать онлайн «Christopher Negus - Linux Bible» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: unrecognised, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Linux Bible: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Linux Bible»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

The industry favorite Linux guide
Linux Bible, 10th Edition This useful guide assumes a base of little or no Linux knowledge, and takes you step by step through what you need to know to get the job done.
Get Linux up and running quickly Master basic operations and tackle more advanced tasks Get up to date on the recent changes to Linux server system management Bring Linux to the cloud using Openstack and Cloudforms Simplified Linux administration through the Cockpit Web Interface Automated Linux Deployment with Ansible Learn to navigate Linux with Amazon (AWS), Google (GCE), and Microsofr Azure Cloud services 
 is the one resource you need, and provides the hands-on training that gets you on track in a flash.

Linux Bible — читать онлайн ознакомительный отрывок

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Linux Bible», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

BIGNUM=1024 let RESULT=$BIGNUM/16 RESULT=`expr $BIGNUM / 16` RESULT=`echo "$BIGNUM / 16" | bc` let foo=$RANDOM; echo $foo

Another way to grow a variable incrementally is to use $(())notation with ++Iadded to increment the value of I. Try typing the following:

$ I=0 $ echo "The value of I after increment is $((++I))" The value of I after increment is 1 $ echo "The value of I before and after increment is $((I++)) and $I" The value of I before and after increment is 1 and 2

Repeat either of those commands to continue to increment the value of $I.

NOTE

Although most elements of shell scripts are relatively freeform (where white space, such as spaces or tabs, is insignificant), both letand exprare particular about spacing. The letcommand insists on no spaces between each operand and the mathematical operator, whereas the syntax of the exprcommand requires white space between each operand and its operator. In contrast to those, bcisn't picky about spaces, but it can be trickier to use because it does floating-point arithmetic.

To see a complete list of the kinds of arithmetic that you can perform using the letcommand, type help letat the bash prompt.

Using programming constructs in shell scripts

One of the features that makes shell scripts so powerful is that their implementation of looping and conditional execution constructs is similar to those found in more complex scripting and programming languages. You can use several different types of loops, depending on your needs.

The ″if…then″ statements

The most commonly used programming construct is conditional execution, or the ifstatement. It is used to perform actions only under certain conditions. There are several variations of ifstatements for testing various types of conditions.

The first if…thenexample tests if VARIABLEis set to the number 1. If it is, then the echocommand is used to say that it is set to 1. The fistatement then indicates that the ifstatement is complete, and processing can continue.

VARIABLE=1 if [ $VARIABLE -eq 1 ] ; then echo "The variable is 1" fi

Instead of using -eq, you can use the equal sign ( =), as shown in the following example. The =works best for comparing string values, while -eqis often better for comparing numbers. Using the elsestatement, different words can be echoed if the criterion of the ifstatement isn't met ( $STRING = ″Friday″). Keep in mind that it's good practice to put strings in double quotes.

STRING="Friday" if [ $STRING = "Friday" ] ; then echo "WhooHoo. Friday." else echo "Will Friday ever get here?" fi

You can also reverse tests with an exclamation mark ( !). In the following example, if STRINGis not Monday, then ″At least it's not Monday″is echoed.

STRING="FRIDAY" if [ "$STRING" != "Monday" ] ; then echo "At least it's not Monday" fi

In the following example, elif(which stands for “else if”) is used to test for an additional condition (for example, whether filenameis a file or a directory).

filename="$HOME" if [ -f "$filename" ] ; then echo "$filename is a regular file" elif [ -d "$filename" ] ; then echo "$filename is a directory" else echo "I have no idea what $filename is" fi

As you can see from the preceding examples, the condition you are testing is placed between square brackets [ ]. When a test expression is evaluated, it returns either a value of 0, meaning that it is true, or a 1, meaning that it is false. Notice that the echolines are indented. The indentation is optional and done only to make the script more readable.

Table 7.1lists the conditions that are testable and is quite a handy reference. (If you're in a hurry, you can type help teston the command line to get the same information.)

TABLE 7.1 Operators for Test Expressions

Operator What Is Being Tested?
-a file Does the file exist? (same as -e)
-b file Is the file a block special device?
-c file Is the file character special (for example, a character device)? Used to identify serial lines and terminal devices.
-d file Is the file a directory?
-e file Does the file exist? (same as -a)
-f file Does the file exist, and is it a regular file (for example, not a directory, socket, pipe, link, or device file)?
-g file Does the file have the set group id (SGID) bit set?
-h file Is the file a symbolic link? (same as -L)
-k file Does the file have the sticky bit set?
-L file Is the file a symbolic link?
-n string Is the length of the string greater than 0 bytes?
-O file Do you own the file?
-p file Is the file a named pipe?
-r file Is the file readable by you?
-s file Does the file exist, and is it larger than 0 bytes?
-S file Does the file exist, and is it a socket?
-t fd Is the file descriptor connected to a terminal?
-u file Does the file have the set user id (SUID) bit set?
-w file Is the file writable by you?
-x file Is the file executable by you?
-z string Is the length of the string 0 (zero) bytes?
expr1 -a expr2 Are both the first expression and the second expression true?
expr1 -o expr2 Is either of the two expressions true?
file1 -nt file2 Is the first file newer than the second file (using the modification time stamp)?
file1 -ot file2 Is the first file older than the second file (using the modification time stamp)?
file1 -ef file2 Are the two files associated by a link (a hard link or a symbolic link)?
var1 = var2 Is the first variable equal to the second variable?
var1 -eq var2 Is the first variable equal to the second variable?
var1 -ge var2 Is the first variable greater than or equal to the second variable?
var1 -gt var2 Is the first variable greater than the second variable?
var1 -le var2 Is the first variable less than or equal to the second variable?
var1 -lt var2 Is the first variable less than the second variable?
var1 != var2 Is the first variable not equal to the second variable?
var1 -ne var2 Is the first variable not equal to the second variable?

There is also a special shorthand method of performing tests that can be useful for simple one-command actions . In the following example, the two pipes ( ||) indicate that if the directory being tested for doesn't exist ( -d dirname), then make the directory ( mkdir $dirname):

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Linux Bible»

Представляем Вашему вниманию похожие книги на «Linux Bible» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Linux Bible»

Обсуждение, отзывы о книге «Linux Bible» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x