-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.sh
executable file
·51 lines (43 loc) · 1.68 KB
/
variables.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
#!/bin/bash
#pwd
#A shell variable is capable enough to hold a single value. These variables are called scalar variables.
#Variable Types
#When a shell is running, three main types of variables are present −
#
#Local Variables −
#A local variable is a variable that is present within the current instance of the shell. It is not available to
#programs that are started by the shell. They are set at the command prompt.
#
#Environment Variables −
#An environment variable is available to any child process of the shell. Some programs need environment variables in
#order to function correctly. Usually, a shell script defines only those environment variables that are needed by the programs that it runs.
#
#Shell Variables −
#A shell variable is a special variable that is set by the shell and is required by the shell in order to function
#correctly. Some of these variables are environment variables whereas others are local variables.
# by convention variable names are in uppercase
CURRENT_DIR=pwd
echo $CURRENT_DIR
VAR_1='Anurag Gundappa'
# to access the variable value prefix its name with $
echo $VAR_1
# making variables read-only
NAME="Zara Ali"
readonly NAME
# error readonly variable cannot be modified
#NAME='Anurag'
# Unsetting variables
PHONE="9975753003"
unset PHONE
echo $PHONE
#Unix / Linux - Special Variables
echo $HOME
echo "The filename of the current script", $0
echo $n
echo "The number of arguments supplied to a script", $#
echo $*
echo $@
echo "The exit status of the last command executed", $?
echo "The process number of the current shell.
For shell scripts, this is the process ID under which they are executing", $$
echo "The process number of the last background command", $!