Embedded Training Content --Bash Programming
时间:2009-08-08 来源:creatory
#!/bin/sh
if [ -e lock ];then
echo "file exists"
echo "delete it now..."
rm -f lock
echo "done"
else
echo "file not exists"
echo "create it now..."
>lock
# touch lock
echo "done"
fi
#!/bin/bash
case `uname -s` in
*Linux*)
os="Linux";;
*UNIX*)
os="UNIX";;
*)
os="unknown";;
esac
case `uname -r` in
?.6.*)
kernel="2.6";;
?.4.*)
kernel="2.4";;
*)
kernel="unknown";;
esac
architecture=`uname -m`
case $architecture in
i?86)
machine="x86 series";;
*)
machine="non-x86 series";;
esac
#output the gathered info
echo "OS=$os,Kernel=$kernel,architecture=$machine"
#!/bin/bash
cpu=` cat /proc/cpuinfo | grep "model name" `
case $cpu in
*Celeron*)
productor="Intel Celeron"
case $cpu in
*\ M\ *)
mobile="yes";;
*)
mobile="no";;
esac
;;
*AMD*)
productor="AMD Com.";;
*)
productor="unknown com.";;
esac
echo "CPU Productor:<$productor>,MobileVersion:<$mobile>"
#!/bin/bash
[ -f lock ] ||exit 0
echo "lock file exist."
echo "begin to delete it..."
[ -f lock ] && rm -f lock
echo "delete it ok"
#!/bin/bash
#this script can enumerate all files of a directory
#and check if a file is executable then execute it
#remain problem:
#The variable i get value from `ls $dir` but it's a dead loop and it can only get executable files except regular files
#what's the matter?
#The problem hasn't been solved.
echo "begin"
index=1
dir=/home/creatory/Test/20090805_Wednesday/
#ls $dir
if test -d $dir;then
for i in `ls $dir` ;do
echo "No:$index Filename:$i"
index=`expr $index + 1`
# [ -f $i ] || continue
if [ -x $i ];then
echo executing $i ...
$dir/$i
else
echo skipping $i,no executable permission.
fi
sleep 1
done
else
echo $dir does not exists.
fi
echo "end"
#!/bin/bash
#this script demonstrates how to use environment variables in shell script
#alternative choice style in case : value1 | value2 )
#for example: root|creatory)
#$LOGNAME
case $LOGNAME in
#root|creatory)
root)
echo "You've sovereign permission.You can do everyting what you want."
;;
*)
echo "Your permission is restricted.Some important operation are being protected."
;;
esac
author:[email protected]
modify time:08/08/2009 training time:08/05/2008 Wednesday
place:ZPark,Beijing,China
if [ -e lock ];then
echo "file exists"
echo "delete it now..."
rm -f lock
echo "done"
else
echo "file not exists"
echo "create it now..."
>lock
# touch lock
echo "done"
fi
#!/bin/bash
case `uname -s` in
*Linux*)
os="Linux";;
*UNIX*)
os="UNIX";;
*)
os="unknown";;
esac
case `uname -r` in
?.6.*)
kernel="2.6";;
?.4.*)
kernel="2.4";;
*)
kernel="unknown";;
esac
architecture=`uname -m`
case $architecture in
i?86)
machine="x86 series";;
*)
machine="non-x86 series";;
esac
#output the gathered info
echo "OS=$os,Kernel=$kernel,architecture=$machine"
#!/bin/bash
cpu=` cat /proc/cpuinfo | grep "model name" `
case $cpu in
*Celeron*)
productor="Intel Celeron"
case $cpu in
*\ M\ *)
mobile="yes";;
*)
mobile="no";;
esac
;;
*AMD*)
productor="AMD Com.";;
*)
productor="unknown com.";;
esac
echo "CPU Productor:<$productor>,MobileVersion:<$mobile>"
#!/bin/bash
[ -f lock ] ||exit 0
echo "lock file exist."
echo "begin to delete it..."
[ -f lock ] && rm -f lock
echo "delete it ok"
#!/bin/bash
#this script can enumerate all files of a directory
#and check if a file is executable then execute it
#remain problem:
#The variable i get value from `ls $dir` but it's a dead loop and it can only get executable files except regular files
#what's the matter?
#The problem hasn't been solved.
echo "begin"
index=1
dir=/home/creatory/Test/20090805_Wednesday/
#ls $dir
if test -d $dir;then
for i in `ls $dir` ;do
echo "No:$index Filename:$i"
index=`expr $index + 1`
# [ -f $i ] || continue
if [ -x $i ];then
echo executing $i ...
$dir/$i
else
echo skipping $i,no executable permission.
fi
sleep 1
done
else
echo $dir does not exists.
fi
echo "end"
#!/bin/bash
#this script demonstrates how to use environment variables in shell script
#alternative choice style in case : value1 | value2 )
#for example: root|creatory)
#$LOGNAME
case $LOGNAME in
#root|creatory)
root)
echo "You've sovereign permission.You can do everyting what you want."
;;
*)
echo "Your permission is restricted.Some important operation are being protected."
;;
esac
author:[email protected]
modify time:08/08/2009 training time:08/05/2008 Wednesday
place:ZPark,Beijing,China
相关阅读 更多 +