随笔分类 -  linux shell编程

摘要:#!/bin/bashROOT_UID=0E_WRONG_USER=65if [ "$UID" -ne "$ROOT_UID" ]thenecho;echo "You must be root to run this script.";echoexit $E_WRONG_USERfiROOTUSER_NAME=root username=`id -nu` if [ "$username" != "... 阅读全文
posted @ 2010-06-01 14:10 waynechen 阅读(347) 评论(0) 推荐(0)
摘要:awk '{printf "host "$3" {\n"" hardware ethernet "$1";\n"" fixed-address "$2";\n""}\n"}' youfile效果:host D2 { hardware ethernet 192.168.0.65; fixed-address 00:26:18:08:49:8B;}host F5 { hardware ether... 阅读全文
posted @ 2010-05-31 15:47 waynechen 阅读(969) 评论(0) 推荐(1)
摘要:第一种:   area[11]=23  area[22]=25echo "area[11]=${area[11]}"第二种:   area2=(zero one two three four)echo "area2[0]=${area[0]}" 第三种:  area3([11]=23 [22]=25)echo "area[11]=${area[11]}"#!/bin/bashline[1]="I ... 阅读全文
posted @ 2010-05-28 17:46 waynechen 阅读(564) 评论(0) 推荐(1)
摘要:#!/bin/bash#and listif [ ! -z "$1" ]&&echo "argument #1=$1"&&[ ! -z "$2" ]&&echo "argment #2=$2"thenecho "at least 2 argumnets passed to script."elseecho "less than 2 arguments... 阅读全文
posted @ 2010-05-28 17:14 waynechen 阅读(383) 评论(0) 推荐(0)
摘要:#!/bin/bashmonth_length(){monthD="31 28 31 30 31 30 31 31 30 31 30 31"echo "$monthD"|awk '{print $"'${1}'"}'}echo "INPUT MONTH:"read monthechodays_in=$(month_length $month)echo "The $month month days ... 阅读全文
posted @ 2010-05-20 10:41 waynechen 阅读(138) 评论(0) 推荐(1)
摘要:#!/bin/bashE_PARAM_ERR=198EQUAL=199max2(){if [ -z "$2" ]thenreturn $E_PARAM_ERRfiif [ "$1" -eq "$2" ]thenreturn $EQUALelseif [ "$1" -gt "$2" ]thenreturn $1elsereturn $2fifi}echo "the first number:"rea... 阅读全文
posted @ 2010-05-18 14:09 waynechen 阅读(7177) 评论(0) 推荐(1)
摘要:#!/bin/bashfunc(){echo "$1"}echo "fist call to function: no arg passed."echo "see if command-line arg is seen."funcechoecho "second call to function: command-line arg passed explicitly."func $1exit 0#... 阅读全文
posted @ 2010-05-18 10:52 waynechen 阅读(369) 评论(0) 推荐(0)