[嵌入式]Shell编程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/simonyucsdy/article/details/79534936
#!/bin/sh
#set varible a
a="hello world"
#print a
echo "A is:"
echo $a

输出:

A is:
hello world

2

#!/bin/sh
#set varible num
num=2
echo "this is the ${num}nd"

输出:

this is the 2nd

3

#!/bin/sh
echo "number of vars:"$#
echo "values of vars:"$*
echo "value of var1:"$1
echo "value of var2:"$2
echo "value of var3:"$3
echo "value of var4:"$4 

运行

./s3 1 2 3 4
输出
number of vars:4
values of vars:1 2 3 4
value of var1:1
value of var2:2
value of var3:3
value of var4:4

4

#!/bin/bash
hello="var1"
echo $hello
function func1 {
	local hello="var2"
	echo $hello
	}
func1
echo $hello

运行输出

var1
var2
var1

5

#!/bin/sh 
folder=/home 
[ -r "$folder" ] && echo "Can read $folder" 
[ -f "$folder" ] || echo "this is not file" 

运行输出

Can read /home
this is not file

6

#!/bin/bash 
for day in Sun Mon Tue Wed Thu Fri Sat
do
	echo $day
done 

运行输出

Sun 
Mon 
Tue 
Wed 
Thu 
Fri 
Sat

7

#!/bin/bash 
echo "Hit a key, then hit return."
read Keypress 
case "$Keypress" in
	[A-Z] ) echo "Uppercase letter";;
	[a-z] ) echo "Lowercase letter";;
	[0-9] ) echo "Digit";;
	* ) echo "Punctuation, whitespace, or other";;
esac 

运行输出

8

#!/bin/bash 
for day in "Sun Mon Tue Wed Thu Fri Sat"
do
	echo $day
done 

运行输出

Sun Mon Tue Wed Thu Fri Sat

猜你喜欢

转载自blog.csdn.net/simonyucsdy/article/details/79534936