Variables:
- its store infromation in memory
- key and value ==> name_varaible and value will be value of the key
rules for Variables:
- name must be start with letter or “_”
- contain only letters , “_” and numbers
- no space bettween key and value
- name=ram
- case-sentive
- Name , name
- Enviromnent variable use captial & scprit or automation use small letters
- $JAVA_HOME
- $java_path
Types of variables:
- local variable (shell)
- enviroment variables
- special variables
- Array variables
- read-only variables
local Variables
- Ex:1
name=ram
age=30
bloodgroup=A-positive
echo "my name is $name and age $age , Blood group is $bloodgroup "
- Ex:2
image=ubunt
docker pull $image
enviroment variables
sudo vi /etc/enviromentThis is default enviroment variableexport data_value=9090# this override default values work only when terminal activity
HOME - user directory
USER - current loggined user $(whoami)
PWD - current working dir
BASIC shell:
- file extension “.sh“`
- #!/bin/bash
create file sample.sh and add below cmds
#!/bin/bash
sudo apt-get update
sudo apt-get install git -y
- chmod 755 sample.sh # provide execute permissions
sh sample.shor./sample.sh
special variables:
- It is used in scrpits and automation
$0 – name of the scrpit
$1, $2 … positional args pass in script
#!/bin/bash
# file demo.sh
echo "arg one value $1"
echo "arg one value $3"
-
sh demo.sh 99 567 44
-
$# – number of args passed
