Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Pub Talk Part IV
| ||||||||
Line: 308 to 308 | ||||||||
Please help me to finish or to fix this translation (from Portuguese)Send me a e-mail julio.neves@gmail.com | ||||||||
Added: | ||||||||
> > | next -- PauloSantana - 25 Dec 2017 | |||||||
-- JulioNeves - 30 Sep 2006 |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Pub Talk Part IV | ||||||||
Changed: | ||||||||
< < | ||||||||
> > | ||||||||
Added: | ||||||||
> > | ||||||||
Changed: | ||||||||
< < | ||||||||
> > | This is a very new translation from Portuguese to English. Please contribute to the development of this site indicating errors and and/or suggesting corrections and materials for this person. | |||||||
'My Friend!!! How have you been, mr. bin? Have you done the exercise I asked you to?' |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Pub Talk Part IV | ||||||||
Line: 303 to 303 | ||||||||
'That means that the test command can be replaced by a pair of square brackets ([] ), separated by blank spaces between the arguments, which would considerably increase the legibility of the command, since if would present a syntax similar to the one of other languages and that is why the test command will be used henceforth.' | ||||||||
Changed: | ||||||||
< < | Please help me to finish or to correct this translation (from Portuguese) | |||||||
> > | Please help me to finish or to fix this translation (from Portuguese) | |||||||
Send me a e-mail julio.neves@gmail.com -- JulioNeves - 30 Sep 2006 |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Pub Talk Part IV |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Pub Talk Part IV | ||||||||
Line: 62 to 62 | ||||||||
'But let's change the subject. The last time we met, I was showing you some conditional commands and, when I was thirsty as hell, you asked me how one can test conditions. Let's see the test command, then.' | ||||||||
Changed: | ||||||||
< < | O Comando test | |||||||
> > | The test Command | |||||||
'Well, we are all acquainted to the use of if testing conditions (which are always greater than, less then, greater or equal, less or equal, equal and not equal). When using Shell to test conditions, we can use the test command, but it is a lot more powerful than we can imagine. Let me first show you the main options to test files in a disc:' | ||||||||
Line: 305 to 305 | ||||||||
Please help me to finish or to correct this translation (from Portuguese) | ||||||||
Changed: | ||||||||
< < | Send me a e-mail PubTalk?">julio.neves@gmail.com | |||||||
> > | Send me a e-mail PubTalk? translation">julio.neves@gmail.com | |||||||
-- JulioNeves - 30 Sep 2006 |
Line: 1 to 1 | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Pub Talk Part IV | |||||||||||||||||||
Line: 55 to 56 | |||||||||||||||||||
chico can't be seen anywhere around | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | Remember the trick: most of the commands have a standard output and an error output (grep is one of the few exceptions) and we should pay attention when it is necessary to send them to the black hole. | ||||||||||||||||||
> > | ![]() grep is one of the few exceptions because it shows no error message when it doesn't find a string) and we should pay attention when it is necessary to send them to the black hole.
| ||||||||||||||||||
'But let's change the subject. The last time we met, I was showing you some conditional commands and, when I was thirsty as hell, you asked me how one can test conditions. Let's see the test command, then.' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | The test command 'Well, we are all acquainted to the use of "if" testing conditions (which are always bigger, smaller, equivalent, etc). When using Shell to test conditions, we can use the test command, but it is a lot more powerful than we can imagine. Let me first show you the main options to test files in a disc:' | ||||||||||||||||||
> > | O Comando test | ||||||||||||||||||
Added: | |||||||||||||||||||
> > | 'Well, we are all acquainted to the use of if testing conditions (which are always greater than, less then, greater or equal, less or equal, equal and not equal). When using Shell to test conditions, we can use the test command, but it is a lot more powerful than we can imagine. Let me first show you the main options to test files in a disc:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | Options of the test command to files Option True if: -e arq arq does exist -s arq arq does exist and is bigger than zero -f arq arq does exist and is a regular file -d arq arq does exist and is a directory -r arq arq does exist with reading privileges -w arq arq does exist with writing privileges -x arq arq does exist with execution privileges | ||||||||||||||||||
> > |
| ||||||||||||||||||
'Now, the main testing options for character chains:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | Options of the test command for character chains Option True if: -e chain chain size is zero -n chain chain size is bigger than zero chain the chain chain is bigger than zero c1 = c2 chains 1 and 2 (c1 & c2) are identical | ||||||||||||||||||
> > |
| ||||||||||||||||||
'Thinking it's over? So sorry!!! Now the part you are not acquainted to, comparisons with numbers. Check out the table below:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | Options of the test command for numbers Option True if Meaning n1 -eq n2 n1 equals n2 equal n1 -ne n2 n1 and n2 are different not equal n1 -gt n2 n1 is greater than n2 greater than n1 -ge n2 n1 is greater or equals than n2 greater or equal n1 -lt n1 n1 is less than n2 less than n1 -le n2 n1 is less or equals than n2 less or equal | ||||||||||||||||||
> > |
| ||||||||||||||||||
'Furthermore, consider the following operators' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | Operators Operator Purpose Parenthesis ( ) Grouping Exclamation ! Denying -a logical And -o logical Or | ||||||||||||||||||
> > |
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'Wow! As you've seen, there is a lot of stuff here, and as I told you, our if is much more powerful than others's. Let's see some examples of how it works, first, testing the existence of a directory:' | ||||||||||||||||||
> > | 'Wow! As you've seen, there is a lot of stuff here, and as I told you, our if is much more powerful than others's. Let's see some examples of how it works, first, testing the existence of a directory:' | ||||||||||||||||||
Example: | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
if test -d lmb then cd lmb | |||||||||||||||||||
Line: 113 to 129 | |||||||||||||||||||
mkdir lmb cd lmb fi | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'That example tests if there is a lmb directory, or else, it creates such directory. I know you will probably question this logic saying the script is not optimized. I know, but I wanted you to understand it the way it is, so that we can use an exclamation point (!) to deny the test command. Check it:' | ||||||||||||||||||
> > | 'That example tests if there is a lmb directory, or else, it creates such directory. I know you will probably question this logic saying the script is not optimized. I know, but I wanted you to understand it the way it is, so that we can use an exclamation point (!) to deny the test command. Check it:' | ||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
if test ! -d lmb then mkdir lmb fi cd lmb | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'This way, the lmb directory would be created if (and only if) it did not exist. This denial comes from the exclamation point (!) that preceeds the option -d. At the end of the execution of this piece of script, you would certainly be in the lmb directory. | ||||||||||||||||||
> > | 'This way, the lmb directory would be created if (and only if) it did not exist. This denial comes from the exclamation point (!) that preceeds the option -d . At the end of the execution of this piece of script, you would certainly be in the lmb directory. | ||||||||||||||||||
Let's see other two examples to check the difference between numbers and chains.' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | cad1=1 cad2=01 if test $cad1 = $cad2 | ||||||||||||||||||
> > | str1=1 str2=01 if test $str1 = $str2 | ||||||||||||||||||
then | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | echo As variáveis são iguais. | ||||||||||||||||||
> > | echo The variables are equal. | ||||||||||||||||||
else | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | echo As variáveis são diferentes. | ||||||||||||||||||
> > | echo The variables are not equal. | ||||||||||||||||||
fi | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
'Running the piece of software above, the answer would be:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | As variáveis são diferentes. | ||||||||||||||||||
> > | The variables are not equal. | ||||||||||||||||||
'Now, let's change it in order to have a numerical comparison:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | cad1=1 cad2=01 if test $cad1 -eq $cad2 | ||||||||||||||||||
> > | str1=1 str2=01 if test $str1 -eq $str2 | ||||||||||||||||||
then | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | echo As variáveis são iguais. | ||||||||||||||||||
> > | echo The variables are equal. | ||||||||||||||||||
else | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | echo As variáveis são diferentes. | ||||||||||||||||||
> > | echo The variables are not equal. | ||||||||||||||||||
fi | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
'And let's run it again:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | As variáveis são iguais. | ||||||||||||||||||
> > | The variables are equal. | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'As you have seen above, we've had twoo different results because the chain 01 is quite different from the chain 1, though they are the same when considered numerically, since the number 1 is equivalent to the number 01.' | ||||||||||||||||||
> > | 'As you have seen above, we've had two different results because the string 01 is quite different from the chain string 1 , though they are the same when considered numerically, since the number 1 is equivalent to the number 01 .' | ||||||||||||||||||
Examples: | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'In order to show the use of conectors -o (OR) and -a (AND), check this example made at the prompt:' | ||||||||||||||||||
> > | 'In order to show the use of conectors -o (OR) and -a (AND), check this example made at the prompt:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | *** ... *** | ||||||||||||||||||
> > | $ Familia=felinae
$ Genero=cat
$ if test $Familia = canidea -a $Genero = lobo -o $Familia = felino -a $Genero = lion
> then
> echo Be aware
> else
> echo Can wave it
> fi
Can wave it
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | Hint: The angle brackets (>) in the begining of the internal lines of the if are the continuation prompts (that are defined as $PS2) and when our friend Shell identifies that a command will have a continuation in the following line, it automatically places it until the end of the command. | ||||||||||||||||||
> > | |||||||||||||||||||
'Let's change the example to check if it still works:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | *** ... *** | ||||||||||||||||||
> > | $ Familia=felino
$ Genero=cat
$ if test $Familia = felino -o $Familia = canideo -a $Genero = lion -o $Genero = lobo
> then
> echo be aware
> else
> echo Can wave it
> fi
Be aware
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'The operation has, obviously, generated an error. That has happened because the option -a preceeds the option -o. This way, what was firstly evaluated was the expression:' | ||||||||||||||||||
> > | 'The operation has, obviously, generated an error. That has happened because the option -a preceeds the option -o . This way, what was firstly evaluated was the expression:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | $Familia = canideo -a $Genero = onça | ||||||||||||||||||
> > | $Familia = canideo -a $Genero = lion | ||||||||||||||||||
'That expression was evaluated as false, so that the answer was:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | $Familia = felino -o FALSO -o $Genero = lobo | ||||||||||||||||||
> > | $Familia = felino -o FALSE -o $Genero = lobo | ||||||||||||||||||
'Solved, it would be:' | |||||||||||||||||||
Changed: | |||||||||||||||||||
< < | VERDADEIRO -o FALSO -o FALSO | ||||||||||||||||||
> > | TRUE -o FALSE -o FALSE | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'Since all the conectors are -o, the final expression has resulted as true (considering that, when in a series of logical expressions connected by logic OR, only one of those expressions must be true to the result become true) and the "then" was wrongly executed. To make it work properly (again), let's try the following procedure:' | ||||||||||||||||||
> > | 'Since all the conectors are -o , the final expression has resulted as TRUE (considering that, when in a series of logical expressions connected by logic OR, only one of those expressions must be true to the result become true) and the then was wrongly executed. To make it work properly (again), let's try the following procedure:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | *** ... *** | ||||||||||||||||||
> > | $ if test \($Familia = felino -o $Familia = canideo\) -a \($Genero = lion -o $Genero = lobo\)
> then
> echo Be aware
> else
> echo Can wave it
> fi
Can wave it
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'This way, using the parentheses, the expressions are grouped with the connector -o, which priorizes the execution and results in:' | ||||||||||||||||||
> > | 'This way, using the parentheses, the expressions are grouped with the connector -o , which priorizes the execution and results in:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | VERDADEIRO -a FALSO | ||||||||||||||||||
> > | TRUE -a FALSE | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'The result of expressions connected by the operator -a is true when all the expressions that it connects are true (which is not the case above). This way, the result was false and the "else" was correctly executed.' | ||||||||||||||||||
> > | 'The result of expressions connected by the operator -a is true when all the expressions that it connects are true (which is not the case above). This way, the result was FALSE and the else was correctly executed.' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'If we decide to read a CD with songs of different singers, we could be temptated to use an if with a connector -a, but it is better to bare in mind that bash provides us many resources, and it could be done more easily with a single grep command, as in the following example:' | ||||||||||||||||||
> > | 'If we decide to read a CD with songs of different singers, we could be temptated to use an if with a connector -a , but it is better to bare in mind that bash provides us many resources, and it could be done more easily with a single grep command, as in the following example:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | *** ... *** | ||||||||||||||||||
> > | $ grep Musician1 musics | grep Musician2
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'Similarly, if we pick a CD with songs of an artist1 and of an artist2, it is not necessary to use an if with the connector -o. The egrep (or grep -E, which is more proper for that situation) can also solve this problem. Check it out:' | ||||||||||||||||||
> > | 'Similarly, if we pick a CD with songs of an Musician1 and of an Musician2 , it is not necessary to use an if with the connector -o . The egrep (or grep -E , which is more proper for that situation) can also solve this problem. Check it out:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | *** ... *** | ||||||||||||||||||
> > | $ egrep (Musician1|Musician2) musics
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'Or (specifically for that case) grep itself could help us out:' | ||||||||||||||||||
> > | 'Or (specifically for that case) grep itself could help us out:' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | *** ... *** | ||||||||||||||||||
> > | $ grep Musician[12] musics
| ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'Above, a regular expression was used. The vertical bar (|) works as a logical OR and the parentheses are used to limit that OR. On the next grep, on the other hand, the word Artista must be followed by one of the values of the list between square brackets [ ], that means, 1 or 2.' | ||||||||||||||||||
> > | 'Above, a regular expression was used. The vertical bar (|) works as a logical OR and the parentheses are used to limit that OR. On the next grep , on the other hand, the word Artista must be followed by one of the values of the list between square brackets ([] ), that means, 1 or 2 .' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'OK! I accept it when you tell me that shell's if is much more powerful than other's. But let me tell you one thing: that syntax if text.. is quite creepy.. han?' | ||||||||||||||||||
> > | 'OK! I accept it when you tell me that shell's if is much more powerful than other's. But let me tell you one thing: that syntax if test... is quite creepy... han?' | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'Yeah, I think you're right. I don't like it either... no one does, I guess. I think that's why Shell has another syntax to substitute the test command.' | ||||||||||||||||||
> > | 'Yeah, I think you're right. I don't like it either... no one does, I guess. I think that's why Shell has another syntax to substitute the test command.' | ||||||||||||||||||
Examples 'In order to do so, we'll use that example to switch directories. It was like that:' | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
if test ! -d lmb then mkdir lmb fi cd lmb | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
'Using a new syntax, it will be:' | |||||||||||||||||||
Added: | |||||||||||||||||||
> > | |||||||||||||||||||
if [ ! -d lmb ] then mkdir lmb fi cd lmb | |||||||||||||||||||
Added: | |||||||||||||||||||
> > |
'That means that the test command can be replaced by a pair of square brackets ([] ), separated by blank spaces between the arguments, which would considerably increase the legibility of the command, since if would present a syntax similar to the one of other languages and that is why the test command will be used henceforth.'
Please help me to finish or to correct this translation (from Portuguese) | ||||||||||||||||||
Changed: | |||||||||||||||||||
< < | 'That means that the test command can be replaced by a pair of square brackets [ ], separated by blank spaces between the arguments, which would considerably increase the legibility of the command, since if would present a syntax similar to the one of other languages and that is why the test command will be used henceforth.' | ||||||||||||||||||
> > | Send me a e-mail PubTalk?">julio.neves@gmail.com | ||||||||||||||||||
-- JulioNeves - 30 Sep 2006 |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > | Pub Talk Part IV
|