[scott]$ cat sample.sh
#!/bin/bash
#This is basic bash script exmaple.
a=Hello
b='Hello'
c="Hello"
d=123
echo $a
echo $b
echo $c
echo $d
echo "Hello, value of d is $d"
[scott]$ sh sample.sh
Hello
Hello
Hello
123
Hello, value of d is 123
[scott]$
Variables Declaration
[scott]$ cat sample.sh
#!/bin/bash
#This is basic bash script exmaple.
a=Hello
b='Hello'
c="Hello"
d=123
echo $a
echo $b
echo $c
echo $d
echo "Hello, value of d is $d"
echo
echo
declare -i e=123 #e is an integer
declare -r f=999 #f is read-only
declare -l g="king kong" #g is in lower case
declare -u h="Hello World" #h is in upper case
echo $e
echo $f
echo $g
echo $h
[scott]$ sh sample.sh
Hello
Hello
Hello
123
Hello, value of d is 123
123
999
king kong
HELLO WORLD
[scott]$
Built-in Variables
[scott]$ echo $HOME
/u02/test/abc
[scott]$ echo $PWD
/u04/ftp/scott
[scott]$ echo $MACHTYPE
x86_64-redhat-linux-gnu
[scott]$ echo $HOSTNAME
abc12345667890
[scott]$ echo $BASH_VERSION
4.1.2(2)-release
[scott]$ echo $SECONDS
8010
[scott]$ echo $0
-bash
[scott]$
#!/bin/bash
#This is basic bash script exmaple.
a=Hello
b='Hello'
c="Hello"
d=123
echo $a
echo $b
echo $c
echo $d
echo "Hello, value of d is $d"
[scott]$ sh sample.sh
Hello
Hello
Hello
123
Hello, value of d is 123
[scott]$
Variables Declaration
[scott]$ cat sample.sh
#!/bin/bash
#This is basic bash script exmaple.
a=Hello
b='Hello'
c="Hello"
d=123
echo $a
echo $b
echo $c
echo $d
echo "Hello, value of d is $d"
echo
echo
declare -i e=123 #e is an integer
declare -r f=999 #f is read-only
declare -l g="king kong" #g is in lower case
declare -u h="Hello World" #h is in upper case
echo $e
echo $f
echo $g
echo $h
[scott]$ sh sample.sh
Hello
Hello
Hello
123
Hello, value of d is 123
123
999
king kong
HELLO WORLD
[scott]$
Built-in Variables
[scott]$ echo $HOME
/u02/test/abc
[scott]$ echo $PWD
/u04/ftp/scott
[scott]$ echo $MACHTYPE
x86_64-redhat-linux-gnu
[scott]$ echo $HOSTNAME
abc12345667890
[scott]$ echo $BASH_VERSION
4.1.2(2)-release
[scott]$ echo $SECONDS
8010
[scott]$ echo $0
-bash
[scott]$