Shell 练习(一)

#!/bin/bash
your_name="qinjx"
echo $your_name
echo ${your_name}

for skill in Ada Coffe Action Java;do
    echo "I am good at ${skill}Script"
done

your_name="tom"
echo $your_name
your_name="alibaba"
echo $your_name

myUrl="http://www.ccyag.com"
readonly myUrl
myUrl="http://ccyag.com"

your_name="qinjx"
greeting="Hello, "$your_name" !"
greeting_1="Hello, ${your_name} !"
echo $greeting
echo $greeting_1

string="abcd"
echo ${#string}

string="ccyag is my site"
echo ${string:1:4}
echo `expr index "$string" is`

array_name=(
value0
value1
value2
value3
)
array_name[10]=value10

echo ${array_name[@]}

length=${#array_name[@]}
length=${#array_name[*]}
length9=${#array_name[9]}
length10=${#array_name[10]}

echo $length
echo $length9
echo $length10

结果如下:

qinjx
qinjx
I am good at AdaScript
I am good at CoffeScript
I am good at ActionScript
I am good at JavaScript
tom
alibaba
/usercode/file.sh: line 17: myUrl: readonly variable

Hello, qinjx !
Hello, qinjx !
4
cyag
7
value0 value1 value2 value3 value10
5
0
7

你可能感兴趣的:(Shell 练习(一))