Working with variables:
1.Variables are named with alphanumeric characters
2.Names must start with a letter
3.To declare a variable, type its name directly followed with an equals sign, directly followed with a value.Note that there's no space, if you put spaces around the equals sign, you'll get an error when you run the script.
4. If your variable is a string with spaces in it, such a good morning , you'll need to out that string in quotes in the variable declaration.
5. To use these variables, we call them with a dollar sign in front of their name.
Example script:
---------------------------
#!/bin/bash
# This is a basic bash script
a=Hello
b="Good Morning"
c=16
echo $a
echo $b
echo $c
#These variables also work inside of other variables or strings if they're double quoted.
echo "$b! I have $c apples."
-----------------------------
Adding attributes to variables
Declare i in front of the variable marks that variable as an integer.
example: declare -i d=123 #d is an integer
Declare r before a variable marks it as read-only. That means that it can't be modified later arithmetically or with stream manipulation.
example: declare -r e=456 #e is read-only
some built in variables to be aware of:
a. $HOME
b. $PWD
c. $MACHTYPE
d. $HOSTNAME
e. $SECONDS
f. $0 returns the name of the script
There are bunch of variables that can be handy , refer to tldp.org/LDP/abs/html/internalvariables.html
Command Substitution
------------------------
Command substitution can be used to get information back from a command right in the bash script, instead of just running them.
It can be accomplished using a dollar sign with parentheses around a command.
example script:
--
#!/bin/bash
# This is a basic bash script
a=$(pwd)
echo $a
So that's a pretty basic example, but let's take a look at another one. At some point in your script writing you'll want to use the value of some complex command. As an example, let's take a look at finding out how long it takes to get a response from a server. I'm setting the variable a to the result of this command line statement. So if I run this command, I see the result. But now, it's available as a variable within my script that I can use for other operations.
example script:
--
#!/bin/bash
# This is a basic bash script
a=$(ping -c 1 example.com | grep 'bytes from' | cut -d = -f 4)
echo "The ping was $a"
Did you realize there's a 12 word phrase you can speak to your man... that will trigger deep feelings of love and impulsive attractiveness to you buried within his heart?
ReplyDeleteBecause deep inside these 12 words is a "secret signal" that triggers a man's instinct to love, look after and look after you with all his heart...
12 Words That Fuel A Man's Love Response
This instinct is so built-in to a man's genetics that it will drive him to work better than before to take care of you.
Matter of fact, triggering this all-powerful instinct is so important to getting the best possible relationship with your man that the second you send your man one of the "Secret Signals"...
...You will instantly find him open his soul and heart to you in such a way he never expressed before and he will see you as the one and only woman in the galaxy who has ever truly attracted him.