-
Notifications
You must be signed in to change notification settings - Fork 1
/
02_variables_script.sh
executable file
·63 lines (42 loc) · 1.95 KB
/
02_variables_script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
# Variables allow us to store and retrieve values by name.
# Bash Variables are a special case of parameter expension
# Variables are named with alphanumeric characters
# Variable names are case-sensitive
# For example : mygreeting=Hello
mygreeting=Hello
# if we vant to put space in values of variable we have to use double quotes
mygreeting2="Good Morning"
# we can also use numbers
number=6
# using all variables
echo $mygreeting
echo $mygreeting2
echo $number
# we can also reassign the value of variable in the same program
myvar="Hello"
echo "The value of myvar is : $myvar"
# reassigning the value of variable
myvar="Nameste"
echo "Now thw value of myvar is : $myvar"
# we can also make variable as read only variable so that it cant be changed later
declare -r name="Gautam Jha"
echo "My name is $name"
# Now we are trying to change it
name="Rahul" # this line prints an error on the screen
echo "Now the value of variable is $name" # this line gives value of variable as Gautam Jha
# we can also declare a variable that that transform textt into all lowercase or uppercase
# text in loercase
declare -l lowerstring="This is some TEXT!"
echo "The value of the lowerstring variable is : $lowerstring"
# we can change the value of this lowerstring variable also but the property of it will not change it will always show value in lower string
lowerstring="LETS CHANGE THE VALUE!"
echo "Now the value of lowerstring variable is: $lowerstring"
# We can also change it in uppercase
declare -u upperstring="this is some text typed in lowercase in script"
echo "The value of th upperstring variable is $upperstring"
# we can change the value of this upperstring variable also but the property of it will not change it will always show value in upper string.
upperstring="Now I am CHANGING the VALUE"
echo "the value of upperstring variable is $upperstring"
# there are som environment variable defined in our system we can see it by command
# -----> env