SHELL 脚本

disp file info
#files=`find . -name "*" -type f`
files=`ls -Ql | awk -F "\"" '{print $2}'`

IFS_BACKUP="$IFS"

IFS="\n"

for filename in $files
do
	#echo "$filename"
	file "$filename"
done

IFS="$IFS_BACKUP"

lowercase-filename

#!/bin/sh

if [ $# -ne 1 ]
  then
    echo "Usage: $0 -l | -u"
    exit 1
fi

if [ $1 != "-l" -a $1 != "-u" ]
  then
    echo "Usage: $0 -l | -u"
    exit 1
fi

if [ $1 = "-l" ]
  then
    for file in *
      do
        #echo "Processing $file ..."
	#targetFile=`expr "+++$file":'+++\(.*\)'|tr '[A-Z]''[a-z]'`
	targetFile=`expr $file : '\(.*\)' | tr '[A-Z]' '[a-z]'`
	echo "$file -> $targetFile"
	mv $file $targetFile
      done
  else
    for file in *
      do
        #echo "Processing $file ..."
	targetFile=`expr $file : '\(.*\)' | tr '[a-z]' '[A-Z]'`
	echo "$file -> $targetFile"
	mv $file $targetFile
      done
fi

netconfig

ifconfig_cmd="/sbin/ifconfig"
route_cmd="/sbin/route"
interface="eth0"
ip_address="192.168.24.6"
netmask="255.255.255.0"
gateway="192.168.204.1"

$ifconfig_cmd $interface $ip_address netmask $netmask

$route_cmd add default gw $gateway

cat "nameserver 8.8.8.8" > /etc/resolv.conf
cat "nameserver 8.8.4.4" >> /etc/resolv.conf

echo "1" > /proc/sys/net/ipv4/ip_forward

service iptables restart

question

echo -n "Continue[y/n]?"

read answer

case "$answer" in
  y|Y)
  	echo "continue"
	;;
  [yY][eE][sS])
  	echo "continue"
  	;;
  n|N)
  	echo "exit."
	;;
  [nN][oO])
  	echo "exit."
	;;
esac

run

case "$1" in
	[sS][tT][aA][rR][tT])
		echo "starting ..."
	;;
	stop)
		echo "stopping ..."
	;;
	*)
		echo "other command"
	;;
esac

test

 

1.test
test 1.sh
ip=`/sbin/ifconfig eth0 | grep "inet " | awk '{print $2}' | awk -F ":" '{print $2}'`

./app --host $ip

2.test
command1 &
command2

3.test
echo << test3.sh

4.text
HELLO="hello world"

export HELLO

echo $HELLO

sh test5.sh
#HELLO="hello world"

echo $HELLO

6.test
index=1
total=0

while [ "$index" -le "100" ]
do
	#total=`expr $total + $index`
	#let total=total+index	// bash support, dash not support
	let total+=index	// bash support, dash not support

	#index=`expr $index + 1`
	let index++		// bash support, dash not support
done

echo $total
7.test

index=1
total=0

until [ "$index" -gt "1000" ]
do
	x=`expr $index % 2`

	if [ "$x" -eq "0" ]
	then
		total=`expr $total + $index`
	fi

	index=`expr $index + 1`

	if [ "$index" -gt "100" ]
	then
	       break	
       else
	       continue
	fi
done
8.test 
echo $total

for i in {1..9}
do
	for j in {1..9}
	do
		value=`expr $i \* $j`

		if [ $value -le "9" ]
		then
			echo -n "   $value"
		else
			echo -n "  $value"
		fi

		#echo -n $value
	done

	echo 
done

9.test
func()
{
  index=0
  total=$#
  sum=0

  until [ "$index" -ge "$total" ]
  do
	#echo $1

	sum=`expr "$sum" + "$1"`

	#echo $sum

	#echo $#
	shift

	index=`expr $index + 1`
  done

  echo $sum
}

func 1 2 3	#func(1,2,3)
func 1
func 1 3 5 6 7 8

10.test 
#files=`ls`
files=$(ls)	# http://tldp.org/LDP/abs/html/commandsub.html

for filename in $files
do
	echo $filename
done

11.test
index=0
total=$#
sum=0

until [ "$index" -ge "$total" ]
do
	echo ${$index}

	#sum=`expr "$sum" + "$1"`

	#echo $sum

	#echo $#
	#shift

	index=`expr $index + 1`
done

12.test

index=0
total=$#
sum=0

until [ "$index" -ge "$total" ]
do
	#echo $1

	sum=`expr "$sum" + "$1"`

	#echo $sum

	#echo $#
	shift

	index=`expr $index + 1`
done

echo $sum



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值