Programming Fundamentals/Variables/Bash: Difference between revisions

From Wikiversity
Jump to navigation Jump to search
Content deleted Content added
Creating
(No difference)

Revision as of 01:15, 21 November 2016

variables.sh

#!/bin/sh

echo "Variables and Data Types"
i=12345
f=1.23456789012345
s="string"

echo "i: $i"
echo "f: $f"
echo "s: $s"
echo

echo "Constants"
readonly pi=3.14159
readonly c="constant"
echo $pi "  " $c
echo

echo "Arithmetic Operators"
a=3
b=2
echo "a = $a"
echo "b = $b"
echo "a + b = $((a + b))" 
echo "a - b = $((a - b))" 
echo "a * b = $((a * b))" 
echo "a / b = $((a / b))" 
echo

echo "Assignment Operator"
a=$((a + b))
echo "a = a + b is $a"
a=$((a - b))
echo "a = a - b is $a"
a=$((a * b))
echo "a = a * b is $a"
a=$((a / b))
echo "a = a / b is $a"
echo

echo "String Concatenation"
s1="Hello"
s2="world"
echo $s1 $s2"!"
echo 

echo "User Input"
echo -n "What is your name? "
read name
echo "Hello" $name"!"

Try It

Copy and paste the code above into one of the following free online development environments or use your own Bash compiler / interpreter / IDE.

See Also