练习:
使用date单独获取系统当前的年份、月份、日、小时、分钟、秒
#date "+%Y-%m-%d %H:%M:%S"
练习:
1、echo是内部命令还是外部命令?
#type echo
2、其作用?
Output the ARGs
3、如何显示“The year is 2013. Today is 26.”为两行?
#echo -e "The year is 2013. \nToday is 12."
练习:
1、printf是内部命令还是外部命令?
#type printf
2、其作用?
printf formats and prints ARGUMENTS under control of the FORMAT.
3、如何显示“The year is 2013. Today is 26.”为两行?
#printf "The year is 2014.\nToday is 12."
练习:
1、创建目录
(1)在/mnt下创建boot和sysroot;
#mkdir -p /mnt/{boot,sysroot}
(2)在/mnt/boot下创建grub;
#mkdir -p /mnt/boot/grub
(3)在/mnt/sysroot下创建proc, sys, bin, sbin, lib, usr, var, etc, dev, home, root, tmp
a)在/mnt/sysroot/usr下创建bin, sbin, lib
b)在/mnt/sysroot/lib下创建modules
c)在/mnt/sysroot/var下创建run, log, lock
d)在/mnt/sysroot/etc下创建init.d
#mkdir -p /mnt/sysroot/{proc,sys,bin,sbin,lib/modules,usr/{bin,sbin,lib},var/{run,log,lock},etc/init.d,dev,home,root,tmp}
1、创建目录/backup
mkdir /backup
2、复制目录/etc至/backup目录中,并重命名为“etc-当前日期”,如etc-2013-02-26;要求保留文件原来的属性,保持链接文件;
#cp -a /etc/ /mnt/etc-`date +%Y-%m-%d`
作业2:
1、思考:ls命令是否可以显示某目录的整体大小,即包括其内部的所有文件的整体大小?
#du -sh
2、通过帮助手册,学习使用du命令;
#man du
练习:
1、创建a123, cd6, c78m, c1 my, m.z, k 67, 8yu, 789等文件;注意,以上文件是以逗号隔开的,其它符号都是文件名的组成部分;
2、显示所有以a或m开头的文件;
#ls [am]*
3、显示所有文件名中包含了数字的文件;
#ls *[0-9]*
4、显示所有以数字结尾且文件名中不包含空白的文件;
#ls *[^[:space:]]*[0-9]
5、显示文件名中包含了非字母或数字的特殊符号的文件;
#ls [^0-9a-zA-Z]
练习:
1、创建一个用户mandriva,其ID号为2002,基本组为distro(组ID为3003),附加组为linux;
#useradd -u 2002 -g distro -G linux mandriva
2、创建一个用户fedora,其全名为Fedora Community,默认shell为tcsh;
useradd -c "Fedora Community" -s /bin/tcsh fedora
3、修改mandriva的ID号为4004,基本组为linux,附加组为distro和fedora;
#usermod -u 4004 -g linux -a -G distro,fedora mandriva
4、给fedora加密码,并设定其密码最短使用期限为2天,最长为50天;
#passwd -n 2 -x 50 fedora
#echo "mylove" | passwd --stdin fedora
5、将mandriva的默认shell改为/bin/bash;
#usermod -s /bin/bash mandriva
6、添加系统用户hbase,且不允许其登录系统;
#useradd -s /bin/nologin hbase
练习:
1、新建一个没有家目录的用户openstack;
#useradd -M openstack
2、复制/etc/skel为/home/openstack;
#useradd -M openstack
3、改变/home/openstack及其内部文件的属主属组均为openstack;
#chown -R openstack:openstack /home/openstack
4、/home/openstack及其内部的文件,属组和其它用户没有任何访问权限
#chmod -R 700 /home/openstack
练习:
1、统计/usr/bin/目录下的文件个数;
#ls /usr/bin/ | wc -l
2、取出当前系统上所有用户的shell,要求,每种shell只显示一次,并且按顺序进行显示;
#cat /etc/passwd | cut -d: -f7 | sort -u | sed /^$/d
3、思考:如何显示/var/log目录下每个文件的内容类型?
#file `ls /var/log `
4、取出/etc/inittab文件的第6行;
#cat /etc/inittab | head -6 | tail -1
5、取出/etc/passwd文件中倒数第9个用户的用户名和shell,显示到屏幕上并将其保存至/tmp/users文件中;
#cat /etc/passwd | tail -9 | head -1 | cut -d: -f1,7 | tee /tmp/users
6、显示/etc目录下所有以pa开头的文件,并统计其个数;
#ls -d /etc/pa* | wc -l
7、不使用文本编辑器,将alias cls=clear一行内容添加至当前用户的.bashrc文件中;
#echo "alias cls=clear" >> ~/.bashrc
练习:
1、显示/proc/meminfo文件中以不区分大小的s开头的行;
#cat /proc/meminfo | grep -i ^s
2、显示/etc/passwd中以nologin结尾的行;
#cat /etc/passwd | grep "nologin$"
取出默认shell为/sbin/nologin的用户列表
#cat /etc/passwd | grep "nologin$" | cut -d: -f1
取出默认shell为bash,且其用户ID号最小的用户的用户名
#cat /etc/passwd | grep "bash$" | sort -t: -k3 | cut -d: -f1 | head -1
3、显示/etc/inittab中以#开头,且后面跟一个或多个空白字符,而后又跟了任意非空白字符的行;
#grep --color "^#[[:space:]]\{1,\}[^[:space:]]" /etc/inittab
4、显示/etc/inittab中包含了:一个数字:(即两个冒号中间一个数字)的行;
#grep ":[[:alnum:]]:" /etc/inittab
5、显示/boot/grub/grub.conf文件中以一个或多个空白字符开头的行;
#grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf
6、显示/etc/inittab文件中以一个数字开头并以一个与开头数字相同的数字结尾的行;
#grep "^\([[:alnum:]]\).*\1$" /etc/inittab
练习:
1、找出 /proc/cpuinfo 文件中的,1位数,或2位数 并用颜色显示出来;
#egrep --colour "[0-9]|[0-9][0-9]" /proc/cpuinfo
2、找出ifconfig命令结果中的1-255之间的整数;
# ifconfig | egrep "\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>"
3、查找当前系统上名字为root(必须出现在行首)的用户的帐号的相关信息, 文件为/etc/passwd
#cat /etc/passwd | grep "^root" | cut -d: -f5
练习:分析/etc/inittab文件中如下文本中前两行的特征(每一行中出现在数字必须相同),请写出可以精确找到类似两行的模式:
l1:1:wait:/etc/rc.d/rc 1
l3:3:wait:/etc/rc.d/rc 3
#grep "^[[:alpha:]]\([[:alnum:]]\):\1:.*\1$" /etc/inittab
4、显示所有以数字结尾且文件名中不包含空白的文件;
#ls *[^[:space:]]*[0-9]
找出/boot/grub/grub.conf文件中1-255之间的数字;
#egrep "\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>" /boot/grub/grub.conf
练习:写一个脚本,完成以下任务
1、添加5个用户, user1,..., user5
2、每个用户的密码同用户名,而且要求,添加密码完成后不显示passwd命令的执行结果信息;
3、每个用户添加完成后,都要显示用户某某已经成功添加;
#!/bin/bash
for i in {1..5}
do
if `id user$i &> /dev/null` ;then
echo "The user$i is exist."
else
useradd user$i
echo "user$i" | passwd --stdin user$i &> /dev/null
echo "new user finish."
fi
done
条件判断:
如果用户不存在
添加用户,给密码并显示添加成功;
否则
显示如果已经没在,没有添加;
如果用户user6不存在,就添加用户user6
如果/etc/inittab文件的行数大于100,就显示好大的文件;
#[ `wc -l /etc/inittab | cut -d' ' -f1` -gt 100 ] && echo "large file."
如果用户存在,就显示用户已存在;否则,就添加此用户;
如果用户不存在,就添加;否则,显示其已经存在;
如果用户不存在,添加并且给密码;否则,显示其已经存在;
练习,写一个脚本,完成以下要求:
1、添加3个用户user1, user2, user3;但要先判断用户是否存在,不存在而后再添加;
2、添加完成后,显示一共添加了几个用户;当然,不能包括因为事先存在而没有添加的;
3、最后显示当前系统上共有多少个用户;
#!/bin/bash
num=0
for I in `seq 1 $#`
do
if `id $1 &> /dev/null`
then
echo "This user is esxit."
else
useradd $1
let num=$num+1
fi
shift
done
echo "new users $num"
练习,写一个脚本,完成以下要求:
给定一个用户:
1、如果其UID为0,就显示此为管理员;
2、否则,就显示其为普通用户;
如果 UID为0;那么
显示为管理员
否则
显示为普通用户
#!/bin/bash
if ! `id $1 &> /dev/null`
then
echo "this is not user."
exit 8
fi
if [ `id -u $1` -eq 0 ]
then
echo "this is root."
else
echo "this is user."
fi
练习:写一个脚本
判断当前系统上是否有用户的默认shell为bash;
如果有,就显示有多少个这类用户;否则,就显示没有这类用户;
#!/bin/bash
if [ `grep "bash$" /etc/passwd | wc -l` -gt 0 ]
then
echo "`grep "bash$" /etc/passwd | wc -l` shells is bash."
else
echo "no user shell is bash"
fi
练习:写一个脚本
判断当前系统上是否有用户的默认shell为bash;
如果有,就显示其中一个的用户名;否则,就显示没有这类用户;
练习:写一个脚本
给定一个文件,比如/etc/inittab
判断这个文件中是否有空白行;
如果有,则显示其空白行数;否则,显示没有空白行
#!/bin/bash
if [ `grep "^$" /etc/inittab | wc -l` -gt 0 ]
then
echo "`grep "^$" /etc/inittab | wc -l`"
else
echo "no space."
fi
练习:写一个脚本
给定一个用户,判断其UID与GID是否一样
如果一样,就显示此用户为“good guy”;否则,就显示此用户为“bad guy”。
#!/bin/bash
if [ `id -u $1` -eq `id -g $1` ]
then
echo "good guy"
else
echo "bad guy"
fi
进一步要求:不使用id命令获得其id号;
#!/bin/bash
if [ `grep "^$1" /etc/passwd | cut -d':' -f3 ` -eq `grep "^$1" /etc/passwd | cut -d':' -f4` ]
then
echo "good guy"
else
echo "bay guy"
fi
161729 145557 7 5
1397341683
练习:写一个脚本
给定一个用户,获取其密码警告期限;
而后判断用户密码使用期限是否已经小于警告期限;
提示:计算方法,最长使用期限减去已经使用的天数即为剩余使用期限;
如果小于,则显示“Warning”;否则,就显示“OK”。
#!/bin/bash
nowtime=`date +%s`
nowday=$[$nowtime/86400]
olday=`grep "$1" /etc/shadow | cut -d':' -f3`
diffday=$[$nowday-$olday]
wrongday=`grep "$1" /etc/shadow | cut -d':' -f6`
longday=`grep "$1" /etc/shadow | cut -d':' -f5`
if [ $[$longday-$diffday] -gt $wrongday ]
then
echo "OK"
else
echo "warning"
fi
练习:写一个脚本
判定命令历史中历史命令的总条目是否大于1000;如果大于,则显示“Some command will gone.”;否则显示“OK”。
history | tail -1 | cut -d' ' -f3
练习:写一脚本
能接受一个参数(文件路径)
判定:此参数如果是一个存在的文件,就显示“OK.”;否则就显示"No such file."
#!/bin/bash
if [ -e $1 ]
then
echo "OK"
else
echo "No such file."
fi
练习:写一个脚本
给脚本传递两个参数(整数);
显示此两者之和,之乘积;
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Please input two int."
exit 8
fi
sum=$[$1+$2]
mul=$[$1*$2]
echo "sum is $sum"
echo "mul is $mul"
练习:写一个脚本,完成以下任务
1、使用一个变量保存一个用户名;
2、删除此变量中的用户,且一并删除其家目录;
3、显示“用户删除完成”类的信息;
#!/bin/bash
user=$1
if [ ! `id $user` ]
then
echo "this user is not exsit."
exit 8
fi
userdel -r $user
echo "$user is del finish."
sed练习:
1、删除/etc/grub.conf文件中行首的空白符;
#sed /^[[:space:]]/d /etc/grub.conf
2、替换/etc/inittab文件中"id:3:initdefault:"一行中的数字为5;
sed 's@\(id:\)[0-9]\(:initdefault:\)@\15\2@g' /etc/inittab
3、删除/etc/inittab文件中的空白行;
#sed '/^$/d' /etc/inittab
4、删除/etc/inittab文件中开头的#号;
#sed 's/^#//g' /etc/inittab
5、删除某文件中开头的#号及后面的空白字符,但要求#号后面必须有空白字符;
#sed 's/^#[[:space:]]*//g' /etc/inittab
6、删除某文件中以空白字符后面跟#类的行中的开头的空白字符及#
7、取出一个文件路径的目录名称;
echo "/etc/rc.d/" | sed -r 's@^(/.*/)[^/]+/?@\1@g'
基名:
echo "/etc/rc.d/" | sed -r 's@^/.*/([^/]+)/?@\1@g'
练习:
传递一个用户名参数给脚本,判断此用户的用户名跟其基本组的组名是否一致,并将结果显示出来。
#!/bin/bash
if [ `id -u $1` -eq `id -g $1` ]
then
echo "good guy"
else
echo "bad guy"
fi
练习:写一个脚本
传递一个参数(单字符就行)给脚本,如参数为q,就退出脚本;否则,就显示用户的参数;
#!/bin/bash
if [ $1 == "q" ]
then
exit 0
else
echo "$1"
fi
练习:写一个脚本
传递一个参数(单字符就行)给脚本,如参数为q、Q、quit或Quit,就退出脚本;否则,就显示用户的参数;
#!/bin/bash
if [ $1 == "q" ]
then
exit 0
elif [ $1 == "Q" ]
then
exit 0
elif [ $1 == "quit" ]
then
exit 0
elif [ $1 == "QUIT" ]
then
exit 0
else
echo "$1"
fi
练习:
传递三个参数给脚本,第一个为整数,第二个为算术运算符,第三个为整数,将计算结果显示出来,要求保留两位精度。形如:
./calc.sh 5 / 2
#!/bin/bash
echo "scale=2;$1$2$3" | bc
练习:
传递3个参数给脚本,参数均为用户名。将此些用户的帐号信息提取出来后放置于/tmp/testusers.txt文件中,并要求每一行行首有行号。
#/bin/bash
for i in `seq 1 $#`
do
string1="$i `grep "^$1" /etc/passwd`"
echo "$string1" >> /tmp/testusers.txt
shift
done
写一个脚本:
判断当前主机的CPU生产商,其信息在/proc/cpuinfo文件中vendor id一行中。
如果其生产商为AuthenticAMD,就显示其为AMD公司;
如果其生产商为GenuineIntel,就显示其为Intel公司;
否则,就说其为非主流公司;
#!/bin/bash
cpu=`grep "vendor" /proc/cpuinfo | cut -d':' -f2 | tr -d " "`
if [ $cpu == "AuthenticAMD" ]
then
echo "The CPU is AMD"
elif [ $cpu == "GenuineIntel" ]
then
echo "The CPU is Intel"
else
echo "Non mainstream"
fi
写一个脚本:
给脚本传递三个整数,判断其中的最大数和最小数,并显示出来。
#!/bin/bash
max=0
min=0
if [ $1 -ge $2 ]
then
if [ $3 -ge $1 ]
then
max=$3
min=$2
else
max=$1
[ $3 -ge $2 ]&&min=$2||min=$3
fi
else
if [ $3 -ge $2 ]
then
max=$3
min=$1
else
max=$2
[ $3 -ge $1 ]&&min=$1||min=$3
fi
fi
echo "Max:$max"
echo "Min:$min"
写一个脚本:
1、设定变量FILE的值为/etc/passwd
2、依次向/etc/passwd中的每个用户问好,并显示对方的shell,形如:
Hello, root, your shell: /bin/bash
3、统计一共有多少个用户
只向默认shell为bash的用户问声好
#!/bin/bash
FILE=/etc/passwd
LINES=`cat $FILE | wc -l`
for i in `seq 1 $LINES`
do
users=`cat $FILE | head -$i | tail -1 | cut -d':' -f1`
shells=`cat $FILE | head -$i | tail -1 | cut -d':' -f7`
if [ $shells == "/bin/bash" &> /dev/null ]
then
echo "Hello $users,you shell is $shells"
fi
done
echo "Have $i users."
写一个脚本:
1、添加10个用户user1到user10,密码同用户名;但要求只有用户不存在的情况下才能添加;
#!/bin/bash
for i in {1..10}
do
if ! `id user$i &> /dev/null`
then
useradd user$i
echo "user$i" | passwd --stdin user$i &> /dev/null
fi
done
扩展:
接受一个参数:
add: 添加用户user1..user10
del: 删除用户user1..user10
其它:退出
#!/bin/bash
if [ $1 == '-add' ]
then
for i in {1..10}
do
if ! `id user$i &> /dev/null`
then
useradd user$i
echo "user$i" | passwd --stdin user$i &> /dev/null
fi
done
elif [ $1 == '-del' ]
then
for i in {1..10}
do
if `id user$i &> /dev/null`
then
userdel -r user$i
fi
done
else
exit 8
fi
自定义用户adminusers user1,user2,user3,hello,hi
#!/bin/bash
if [ $1 == '-add' ]
then
shift
for i in `seq 1 $#`
do
if ! `id $1 &> /dev/null`
then
useradd $1
echo "$1" | passwd --stdin $1 &> /dev/null
shift
else
echo "The user $1 is exsit."
shift
fi
done
elif [ $1 == '-del' ]
then
shift
for i in `seq 1 $#`
do
if `id $1 &> /dev/null`
then
userdel -r $1
shift
else
echo "The user $1 is no exsit."
shift
fi
done
else
exit 8
fi
写一个脚本:
计算100以内所有能被3整除的正整数的和;
取模,取余:%
3%2=1
100%55=45
#!/bin/bash
sum=0
for i in {1..100}
do
if [ $[$i%3] -eq 0 ]
then
sum=$[$sum+$i]
fi
done
echo "Sum is $sum."
写一个脚本:
计算100以内所有奇数的和以及所有偶数的和;分别显示之;
#!/bin/bash
oddsum=0
evensum=0
for i in {1..100}
do
if [ $[$i%2] -eq 0 ]
then
evensum=$[$evensum+$i]
else
oddsum=$[$oddsum+$i]
fi
done
echo -e "The evensum is $evensum.\n The oddsum is $oddsum."
写一个脚本,分别显示当前系统上所有默认shell为bash的用户和默认shell为/sbin/nologin的用户,并统计各类shell下的用户总数。显示结果形如:
BASH,3users,they are:
root,redhat,gentoo
NOLOGIN, 2users, they are:
bin,ftp
#!/bin/bash
bashshell=/bin/bash
noshell=/bin/nologin
bashsum=`grep "bash$" /etc/passwd | wc -l`
nosum=`grep "nologin$" /etc/passwd | wc -l`
bashuser=`grep "bash$" /etc/passwd | cut -d':' -f1 | tr "\n" "," | sed 's/,$//'`
nouser=`grep "nologin$" /etc/passwd | cut -d':' -f1 | tr "\n" "," | sed 's/,$//'`
echo -e "BASH, $bashsum users , they are \n $bashuser "
echo -e "NOLOGIN, $nosum users , they are \n $nouser "
练习:将/etc/yum.repos.d/server.repo文件中的ftp://instructor.example.com/pub替换为http://172.16.0.1/yum
文件内容如下:
# repos on instructor for classroom use
# Main rhel5 server
[base]
name=Instructor Server Repository
baseurl=ftp://instructor.example.com/pub/Server
gpgcheck=0
# This one is needed for xen packages
[VT]
name=Instructor VT Repository
baseurl=ftp://instructor.example.com/pub/VT
gpgcheck=0
# This one is needed for clustering packages
[Cluster]
name=Instructor Cluster Repository
baseurl=ftp://instructor.example.com/pub/Cluster
gpgcheck=0
# This one is needed for cluster storage (GFS, iSCSI target, etc...) packages
[ClusterStorage]
name=Instructor ClusterStorage Repository
baseurl=ftp://instructor.example.com/pub/ClusterStorage
gpgcheck=0
1、查找/var目录下属主为root并且属组为mail的所有文件;
#find /var -user root -group mail
2、查找/usr目录下不属于root,bin,或student的文件;
#find /usr ! -user root -a ! -user bin -a ! -user student
3、查找/etc目录下最近一周内内容修改过且不属于root及student用户的文件;
#find /etc/ -mtime -7 ! -user root -a ! -user student
4、查找当前系统上没有属主或属组且最近1天内曾被访问过的文件,并将其属主属组均修改为root;
#find / -nouser -a -nogroup -a -atime -1 -exec chown root:root {} \;
5、查找/etc目录下大于1M的文件,并将其文件名写入/tmp/etc.largefiles文件中;
#find /etc/ -size +1M >> /tmp/etc.largefiles
6、查找/etc目录下所有用户都没有写权限的文件,显示出其详细信息;
#find /etc -not -perm /222 -ls
练习:写一个脚本
写一个脚本,显示当前系统上shell为-s指定类型的用户,并统计其用户总数。-s选项后面跟的参数必须是/etc/shells文件中存在的shell类型,否则不执行此脚本。另外,此脚本还可以接受--help选项,以显示帮助信息。脚本执行形如:
./showshells.sh -s bash
显示结果形如:
BASH,3users,they are:
root,redhat,gentoo
如果当前主机的主机名为空,或者为(none),或者为localhost,就将其改为www.magedu.com
写一个脚本,利用RANDOM生成10个随机数,并找出其中的最大值,和最小值;
#!/bin/bash
#declare -i MAX=0
#declare -i MIN=0
MAX=0
MIN=0
for I in {1..10}
do
MYTEST=$RANDOM
[ $I -eq 1 ] && MIN=$MYTEST
if [ $I -le 9 ]
then
echo -n "$MYTEST,"
else
echo -n "$MYTEST"
fi
[ $MYTEST -gt $MAX ] && MAX=$MYTEST
[ $MYTEST -lt $MIN ] && MIN=$MYTEST
done
echo -e "\n $MAX , $MIN"
练习:写一个脚本showlogged.sh,其用法格式为:
showlogged.sh -v -c -h|--help
其中,-h选项只能单独使用,用于显示帮助信息;-c选项时,显示当前系统上登录的所有用户数;如果同时使用了-v选项,则既显示同时登录的用户数,又显示登录的用户的相关信息;如
Logged users: 4.
They are:
root tty2 Feb 18 02:41
root pts/1 Mar 8 08:36 (172.16.100.177)
root pts/5 Mar 8 07:56 (172.16.100.177)
hadoop pts/6 Mar 8 09:16 (172.16.100.177)
#!/bin/bash
declare -i shownum=0
declare -i showuser=0
if [ $# -lt 1 ]
then
echo "Uage: showlogged.sh -v -c -h|--help."
exit 7
fi
for I in `seq 1 $#`
do
case $1 in
-h|--help)
echo "Uage: showlogged.sh -v -c -h|--help."
exit 0 ;;
-v|--version)
let showuser=1
shift ;;
-c|--count)
let shownum=1
shift;;
*)
echo "Uage: showlogged.sh -v -c -h|--help."
exit 7 ;;
esac
done
if [ $shownum -eq 1 ]
then
echo "Logged users: `who | wc -l`"
if [ $showuser -eq 1 ]
then
who
fi
fi
练习:写一个脚本
通过命令行传递一个文件路径参数给脚本:
如果参数多了或少了,报错;
如果参数指定的路径对应的是目录而不是文件,报错;
而后,检查路径指定的文件是否为空或不存在,如果是,则新建此文件,并在文件中生成如下内容
#!/bin/bash
#
而后,使用vim编辑器打开此文件,并让光标处于这个文件的最后一行;
写个脚本,按如下方式执行:
mkscript.sh -v|--version VERSION -a|--author AUTHOR -t|--time DATETIME -d|--description DESCRIPTION -f|--file /PATH/TO/FILE -h|--help
1、此脚本能创建或打开-f选项指向的文件/PATH/TO/FILE;如果其为空文件,能自动为其生成第一行;如果文件不空,且第一行不是#!/bin/bash,则中止此脚本,并报错“The file is not a bash script.";否则,则直接使用vim 打开此文件;
提示:/PATH/TO/FILE,要判断其目录是否存在;如果不存在,则报错;
2、如果为空文件,自动生成的第一行内容为:
#!/bin/bash
3、如果为空文件,且使用了-a选项,则在文件中添加“# Author: -a选项的参数”,比如:
# Author: Jerry
4、如果为空文件,且使用了-t选项,则在文件中添加“# Date: 脚本执行-t选项后指定的时间”,比如:
# Date: 2013-03-08 18:05
5、如果为空文件,且使用了-d选项,则在文件中添加“# Description: -d选项的内容”,比如:
# Description: Create a bash script file head.
6、如果为空文件,且使用了-v选项,则在文件添加“# Version: -v后跟的参数”,比如:
# Version: 0.1
6、-h选项只能单独使用,用于显示使用帮助;
7、其它选项,显示帮助信息;
说明:
这是一个用于创建脚本的脚本,它可以自动帮助创建一个bash脚本的文件头,这样,以后使用此脚本来创建其它脚本将变得比较高效。比如:
#!/bin/bash
# Author: Jerry(jerry@magedu.com)
# Date: 2013-03-08 18:05
# Description: Create a bash script file head.
# Version: 0.1
#