Pages

Saturday, December 12, 2015

declare command one liners

Home

Command declare is used to set variable and functions attributes.

1.       Create a constant variable
A constant variable is a variable that is always constant in the experiment, it never changes.

declare -r var
declare -r varName=value

declare -r pwdfile=/etc/passwd
echo $pwdfile
pwdfile=/etc/foo.txt

2.       Create an integer variable
An integer data type (variable) is any type of number without a fractional part.

declare -i var
declare -i varName=value

declare -i y
y=10
[ $y -eq 0 ] && echo "Y is set to a zero number." || echo "Y is set to a nonzero number."
y="foo"
[ $y -eq 0 ] && echo "Y is set to a zero number." || echo "Y is set to a nonzero number."

3.       Create an array

declare -a arrayname=(element1 element2 element3)




No comments:

Post a Comment