Bash Commands - # Integer or string?

#!/bin/bash
# int-or-string.sh

a=2334
let "a += 1"
echo "a = $a "
echo


b=${a/23/BB}                # Substitute "BB" for "23".
                                        
# This transforms $b into a string.

echo "b = $b"               # b = BB35

declare -i b                    # Declaring it an integer doesn't help.
echo "b = $b"              
# b = BB35


let "b += 1"                     # BB35 + 1
echo "b = $b"                 # b = 1
echo                                # Bash sets the "integer value" of a string to 0.


c=BB34                             # c = BB34

echo "c = $c"

d=${c/BB/12}                   # Substitute  "12" for "BB"

echo "d = $d"                 # 1234

let "d+=1"

echo "d = $d"                  # 1235

exit 0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章