Variables are use to assign the value of data types such as integer, float, string, etc.
In shell scripting no need to specify types for your variable.
Create integer variable
In C language
In C language
int a = 10;
In shell script
In shell script
You should not leave any space between equal sign
a = 10(it will not work)
To access the variable use dollar($) symbol.
Script:
#!/bin/sh
my_variable=10
echo "my variable is $my_variable"my_variable="mystring"
echo "my variable is $my_variable"
my_variable=10
echo "my variable is $my_variable"my_variable="mystring"
echo "my variable is $my_variable"
Output:
my variable is 10
my variable is mystring
If you want to read value to variable from user you have to use 'read' keyword
Script:
echo -n "Enter any value : "
read var
echo "Entered value is $var"
output:
Entered value is 100
No comments:
Post a Comment