You first pick a name for your new variable -- ex. myValue
Then assign the value using the equal sign, with the variable name on the left, expression to be evaluated on the right (no extra spaces):
ex.Complex strings must be put inside quotation marks.
myValue=5000;
myValue=blue;
myValue="Snow White";
To retrieve the value of your variable, add a dollar sign ($) in front of the variable name.
echo $myValue;In the above examples, the output for each would be
5000If you wanted to place the result of a command into a variable, you put the expression inside of parentheses and place a dollar sign in front of the opening paren:
blue
Snow White
myLineCount=$(wc -l myTargetFilename.txt);Output would be:
echo "Number of lines: $myLineCount";
Number of lines: 250 myTargetFilename.txt
No comments :
Post a Comment