bash set variables code example

Example 1: how to set environment variable using bash

# set variable environment
export fullname="restu wahyu saputra"
echo $fullname

Example 2: bash set environment variable

# Linux - Bash

# syntax 
# export *<variable-name>=*<variable-value>;

# example 
export ORACLE_SID='sales_database';

Example 3: bash create variable

#create a variable to store name
name="Lance Armah"

Example 4: assign a variable in bash

#!/bin/bash
# Naked variables

echo

# When is a variable "naked", i.e., lacking the '$' in front?
# When it is being assigned, rather than referenced.

# Assignment
a=879
echo "The value of \"a\" is $a."

# Assignment using 'let'
let a=16+5
echo "The value of \"a\" is now $a."

echo

# In a 'for' loop (really, a type of disguised assignment):
echo -n "Values of \"a\" in the loop are: "
for a in 7 8 9 11
do
  echo -n "$a "
done

echo
echo

# In a 'read' statement (also a type of assignment):
echo -n "Enter \"a\" "
read a
echo "The value of \"a\" is now $a."

echo

exit 0