bash assign string to variable code example

Example 1: bash create variable

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

Example 2: print variable in bash

#!/bin/bash  
echo  
echo "When single quote is used with string:"  
invitation='Welcome to javatpoint'  
echo $invitation  
echo  
echo "When double quote is used with string:"  
invitation="Welcome to javatpoint"  
echo $invitation  
echo  
echo "When variable is used with double quote:"  
Remark="Hello User!, $invitation"  
echo $Remark  
echo  
echo "When variable is used with single quote:"  
Remark='Hello User!, $invitation'  
echo $Remark  
echo

Example 3: php add variable to array

<?php
	$myArray = array(); // Init empty array

	$myArray[] = $value; // Add value to the array
?>

Example 4: bash store string in variable

${!var}	#Just use to use reference value inside another variable ;)

Tags:

Php Example