Wednesday, October 28, 2009

Quoting








 

 






















































Quoting



Four different types of quoting mechanisms are recognized. These are summarized in Table A.5.





















































Table A.5. Summary of Quotes


Quote





Description





'...'





Removes special meaning of all enclosed characters





"..."





Removes special meaning of all enclosed characters except $, `, and \





\c





Removes special meaning of character c that follows; inside double quotes removes special meaning of $, `, ", newline, and \that follows, but is otherwise not interpreted; used for line continuation if appears as last character on line (newline is removed)





`command` or$(command)





Executes command and inserts standard output at that point





Tilde Substitution



Each word and shell variable on a command line is checked to see whether it begins with an unquoted ~. If it does, the rest of the word or variable up to a / is considered a login name and is looked up in a system file, typically /etc/passwd. If that user exists, his home directory replaces the ~ and his login name. If that user doesn't exist, the text is unchanged. A ~ by itself or followed by a / is replaced by the HOME variable.



Arithmetic Expressions



General Format: $((expression))



The shell evaluates the integer arithmetic expression. expression can contain constants, shell variables (which don't have to be preceded by dollar signs), and operators. The operators, in order of decreasing precedence, are





































































































-





unary minus





~





bitwise NOT





!





logical negation





* / %





multiplication, division, remainder





+ -





addition, subtraction





<< >>





left shift, right shift





<= >= < >





comparison





== !=





equal, not equal





&





bitwise AND





^





bitwise exclusive OR





|





bitwise OR





&&





logical AND





||





logical OR





expr1 ? expr2 : expr3





conditional operator





=, *=, /=, %=





assignment





+=, <<=, >>=, &=,



 


^=, |=



 



Parentheses may be used to override operator precedence.



The exit status is zero (true) if the last expression is nonzero and one (false) if the last expression is zero.



The C operators sizeof, ++, and -- may be available in your shell implementation but are not required by the standard.



Examples





y=$((22 * 33))



z=$((y * y / (y - 1)))
















     

     


    No comments: