declare examples & clarifications

[root@test1 ~]# declare -i number=15 --declare the integer value 15 ...i means integer
[root@test1 ~]# echo $number
15
[root@test1 ~]# printf "%d\n" "$number"
15
[root@test1 ~]# declare -i number="davinder"
[root@test1 ~]# echo $number ---> "davinder" is not the integer
0
[root@test1 ~]# printf "%d\n" "$number"
0
[root@test1 ~]# printf "%s\n" "$number"
0
[root@test1 ~]# declare number="davinder"
[root@test1 ~]# printf "%s\n" "$number"
0
[root@test1 ~]# echo $number
0
[root@test1 ~]# declare -p number --> show the number variable status
declare -i number="0"
[root@test1 ~]# declare +i number -->+i reverse the integer
[root@test1 ~]# echo $number
0
[root@test1 ~]# echo $number
0
[root@test1 ~]# declare -p number
declare -- number="0"
[root@test1 ~]# printf "%s\n" "$number"
0
[root@test1 ~]# declare -i number="davinder"
[root@test1 ~]# declare -i number="10"
[root@test1 ~]# echo $number
10
[root@test1 ~]# printf "%d\n" $number
10
[root@test1 ~]# printf "%s\n" $number
10
[root@test1 ~]# number="davinder"
[root@test1 ~]# printf "%s\n" $number
0
[root@test1 ~]# printf "%d\n" $number
0
[root@test1 ~]# declare +i number
[root@test1 ~]# printf "%s\n" $number
0
[root@test1 ~]# number="davinder"
[root@test1 ~]# declare +i number
[root@test1 ~]# printf "%s\n" $number
davinder
[root@test1 ~]# printf "%d\n" $number
-bash: printf: davinder: invalid number
0
[root@test1 ~]# printf "%s\n" $number
davinder

Comments

Popular posts from this blog

How to delete SEA in VIOS

Webmin configuration for LDAP

Sample questions and answers for AWS Associate Solutions Architect Certification ---> AWS exam dumps