Variables can contain the output of a command. (Web hosting control panel)
Variables can contain the output of a command. The advantage of having a variable set to the output of a command is that you can take advantage of information that changes in certain conditions. In the following example, the MACHINE variable is set to the output of the uname -n command. This always sets MACHINE to the name of your current computer, as follows: MACHINE=`uname -n` The command contained within the back quotes is executed in a subshell, and the output is stored in the variable name. In this case, the uname -n command outputs the computer’s hostname (such as baskets.handsonhistory.com) and assigns that value to the MACHINE variable. Note A subshell provides a way to execute a command, or series of commands, outside of the current shell. The subshell is similar to the current shell in that it remembers locations of commands and values of environment variables from the parent shell. However, changes to the subshell’s environment are not automatically passed back to the parent shell. Variables can also take on the values of other variables. This is a way of taking advantage of changing information as the shell script runs. For example, a shell script could determine an account balance ($CurrentBalance) and then store that value in the BALANCE variable, enabling the value to be saved as follows: BALANCE=$CurrentBalance Note When being assigned, only the variable name is necessary. When being referenced, the variable name must be prefaced by a dollar sign ($). Performing arithmetic evaluation in shell scripts While variables in shell scripts can contain numbers, all values are treated as alphanumeric strings unless otherwise instructed by the built-in typeset command. Integer arithmetic can be performed using the built-in let command or through the external expr command. For example, given that the variable BIGNUM contains the value 1024, the following two commands would both store the value 64 in the RESULT variable: let Result=$BIGNUM/16 Result=`expr $BIGNUM / 16` Note While most elements of shell scripts are relatively free form (where white space, such as spaces or tabs, is insignificant), both of the previous commands are particular about spacing. The let command insists on no spaces between each operand and the mathematical operator, whereas the syntax of the expr command requires white space between each operand and its operator. Valid mathematical operations available in bash s built-in let command are listed in Table 12-1 in order of decreasing precedence. Multiple operators in the same row indicate equal precedence. Table 12-2 similarly lists the valid mathematical operators for the expr command. Table 12-1: Mathematical Operations in let Operator Description + - unary plus and minus ! ~ logical and bitwise negation * / % multiplication, division, and modulus (remainder) + - addition and subtraction << > left and right bitwise shift < <= >= > less than; less than or equal to; greater than or equal to; and greater than comparisons
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.