标签:第8周作业
第8周作业
1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。
【集线器】
集线器也称HUB,工作在OSI七层结构的第一层物理层,属于共享型设备,接收数据广播发出,在局域网内一般都是星型连接拓扑结构,每台工作站都连接到集线器上。
由于集线器的带宽共享特性导致网络利用效率极低,一般在大中型的网络中不会使用到集线器。
【网桥】
网桥(Bridge)也称桥接器,是连接两个局域网的存储转发设备,用它可以完成具有相同或相似体系结构网络系统的连接。
网桥和交换机一样都是工作在OSI模型的第二层(数据链路层),可以看成是一个二层路由器(真正的路由器是工作在网络层,根据IP地址进行信包转发)。
网桥可有效的将两个局域网(LAN)连起来,根据MAC地址(物理地址)来转发帧,使本地通信限制在本网段内,并转发相应的信号至另一网段,网桥通常用于联接数量不多的、同一类型的网段。
【二层交换机】
二层交换机工作于OSI模型的第2层(数据链路层),故而称为二层交换机。
二层交换技术的发展已经比较成熟,二层交换机属数据链路层设备,可以识别数据包中的MAC地址信息,根据MAC地址进行转发,并将这些MAC地址与对应的端口记录在自己内部的一个地址表中。
【三层交换机】
三层交换机就是具有部分路由器功能的交换机,三层交换机的最重要目的是加快大型局域网内部的数据交换,所具有的路由功能也是为这目的服务的,能够做到一次路由,多次转发。
对于数据包转发等规律性的过程由硬件高速实现,而像路由信息更新、路由表维护、路由计算、路由确定等功能,由软件实现。
【路由器】
路由器跟集线器和交换机不同,是工作在OSI的第三层(网络层),根据IP进行寻址转发数据包。
路由器是一种可以连接多个网络或网段的网络设备,能将不同网络或网段之间(比如局域网——大网)的数据信息进行转换,并为信包传输分配最合适的路径,使它们之间能够进行数据传输,从而构成一个更大的网络。
路由器具有最主要的两个功能,即数据通道功能和控制功能。数据通道功能包括转发决定、背板转发以及输出链路调度等,一般由特定的硬件来完成;控制功能一般用软件来实现,包括与相邻路由器之间的信息交换、系统配置、系统管理等。
【区别】
网桥 工作在数据链路层
集线器 工作在物理层,所有端口共享一个mac地址,共享带宽
二层交换机 工作在数据链路层,每个端口有自己的mac地址,独享带宽
三层交换机 工作在数据链路层,网络层,拥有部分路由功能
路由器 工作在网络层
2、IP地址的分类有哪些?子网掩码的表示形式及其作用
【IP地址分类】
A类用于大型网络(地址范围1.0.0.0到127.255.255.255,默认掩码255.0.0.0)
B类用于中型网络(地址范围128.0.0.0-191.255.255.255,默认掩码255.255.0.0)
C类用于小型网络(地址范围192.0.0.0-223.255.255.255,默认掩码255.255.255.0)
D类用于组播(地址范围从224.0.0.0到239.255.255.255)
E类用于实验
【子网掩码的表示形式】
①点分十进制,如255.255.255.0
②ip地址后加‘/‘以及[1-32]的数字
【子网掩码的作用】
①区别网络标识和主机标识
②将一个大的IP网络划分为若干小的子网络
3、计算机网络的分成模型有哪些(OSI模型和TCP/IP模型),每一层的功能及涉及到的物理设备有哪些。
【OSI模型】
应用层:提供应用程序之间通信;
表示层:处理数据格式、数据加密;
会话层:建立,维护,管理会话连接涉及操作系统和网络接口和各种数据;
传输层:建立主机端到端连接。涉及物理设备:四层交换机
网络层:寻址和路由选择。涉及物理设备:路由器
数据链路层:提供介质访问,链路管理,将数据分帧并处理流控制。涉及物理设备:网卡,网桥,交换机
物理层:比特流传输,将数据转换为可通过物理介质传送的电子信号。涉及物理设备:双绞线、同轴电缆,集线器
【TCP/IP模型】
应用层(对应OSI模型的应用层,会话层,表示层)
传输层(对应OSI模型的传输层)
网络互联层(对应OSI模型的网络层)
网络接口层(对应OSI模型的数据链路层和物理层)
4、如何将Linux主机接入到TCP/IP网络,请描述详细的步骤。(手动指定的方式)
①使用ifconfig查看网卡配置信息,看主要使用的网卡名称
②到/etc/sysconfig/network-scripts/目录下查找对应的网卡配置文件
③主要配置项
DEVICE(设备名称)
TYPE(设备类型。端口为Ethernet)
ONBOOT(系统启动时读取)
BOOTPROTO=static(ip配置协议。当前为静态ip,可设置DHCP,)
IPADDR(ip地址)
NETMASK(子网掩码)
GATEWAY(网关地址)
DNS1(DNS服务器地址)
④重启网络服务 service network restart
⑤在CLI中输入ping 163.com测试网络连接
5、为Linux主机配置网络信息的方式有哪些,请描述各个过程。
①ifconfig eth0 IP/mask
②ip addr add IP device eth0
③Linux网络属性配置的tui(text user interface):system-config-network-tui
④使用setup图形界面设置
6、写一个脚本,使用ping命令探测172.16.250.1-172.16.250.254之间的所有主机的在线状态;
在线的主机使用绿色显示;
不在线的主使用红色显示;
[root@STCO6 ~]# cat /tmp/ping.sh #!/bin/bash # ip_address=‘172.16.250‘ for i in {1..254};do ping -c 5 -w 5 ${ip_address}.${i} &> /dev/null if [ $? -eq 0 ]; then echo -e "\033[32m ${ip_address}.${i} \033[0m" else echo -e "\033[31;5m ${ip_address}.${i} \033[0m" fi done
7、详细描述每个网络接口的配置文件中各个参数的含义和其所对应的值;
网卡配置文件`/etc/sysconfig/network-scripts/ifcfg-网卡名`
DEVICE #网卡名
BOOTPROTO #ip地址分配方式:dhcp、static
HWADDR #MAC地址
NM_CONTROLLED=yes #network manager参数
ONBOOT= #网卡是否开机激活
TYPE= #网络类型
IPV6INIT=no #禁止IPV6
USERCTL=no #是否允许非root用户控制该设备,为no,只能root用户更改
IPADDR= #IP ADDR
GATEWAY= #gateway地址
NETMASK= #掩码
DNS1= #dns1地址
DNS2= #dns2地址
8、如何给网络接口配置多个地址,有哪些方式?
ifconfig:
ifconfig IFACE_ALIAS IPADDR
ip:
ip addr add ip_addr/mask dev IFACE label alias_label
配置文件:
ifcfg-IFACE_ALIAS
DEVICE=IFACE_ALIAS
9、常用的网络管理类工具有哪些,并用示例形式描述他们的使用方法。
【netstat】
netstat -tan #查看当前系统网络连接情况
-t tcp协议相关连接
-u udp协议相关连接
-l 监听状态的连接
-a 所有连接
-n 以数字显示ip和端口
【route】
route [-nee]
-n 以数字显示ip和端口
-ee 显示详细信息
route add [-net|-host] [网域或主机] netmask [mask] [gw|dev]
[root@itop ~]# route add -host 192.168.100.20 netmask 255.255.255.0 dev eth0
route del [-net|-host] [网域或主机] netmask [mask] [gw|dev]
[root@itop ~]# route del -net 169.254.0.0 netmask 255.255.0.0 dev eth0
【ss】
[root@itop ~]# ss -tnl #与netstat类似,数据量较大时ss更有优势
【ifconfig】
ifconfig 设备名称 up|down
up 启动指定网络设备/网卡。
down 关闭指定网络设备/网卡。
ifconfig 设备名称 ip地址 #配置设备ip地址
ifconfig 设备名称 mtu <字节数>
设置网卡的最大传输单元 (bytes)
10、Linux系统软件包管理方法(安装、升级、卸载等操作)有哪些,以及如何管理的。
rpm命令实现程序管理:
安装:-ivh, –nodeps, –replacepkgs
卸载:-e, –nodeps
升级:-Uvh, -Fvh, –nodeps, –oldpackage
查询:-q, -qa, -qf, -qi, -qd, -qc, -q –scripts, -q –changlog, -q –provides, -q –requires
校验:-V
导入GPG密钥:–import, -K, –nodigest, –nosignature
数据库重建:–initdb, –rebuilddb
Yum 命令实施软件包管理
repolist [all|enabled|disabled]
显示程序包:list
# yum list [all | glob_exp1] [glob_exp2] […]
# yum list {available|installed|updates} [glob_exp1] […]
安装程序包: install package1 [package2] […]
reinstall package1 [package2] […] (重新安装)
升级程序包:
update [package1] [package2] […]
downgrade package1 [package2] […] (降级)
检查可用升级:
check-update
卸载程序包:
remove | erase package1 [package2] […]
查看程序包information:
info […]
查看指定的特性(可以是某文件)是由哪个程序包所提供:
provides | whatprovides feature1 [feature2] […]
清理本地缓存:
clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
构建缓存:
makecache
11、如何使用发行版光盘作为yum repository,请描述该过程。
[root@STCO6~]#vim /etc/yum.repos.d/local.repo [local] name=local_repo baseurl=file:///mnt enabled=1 gpgcheck=0 [root@STCO6~]#yum clean all [root@STCO6~]#yum makecache
12、写一个脚本,完成以下功能
(1) 假设某目录(/etc/rc.d/rc3.d/)下分别有K开头的文件和S开头的文件若干;
(2) 显示所有以K开头的文件的文件名,并且给其附加一个stop字符串;
(3) 显示所有以S开头的文件的文件名,并且给其附加一个start字符串;
(4) 分别统计S开头和K开头的文件各有多少;
方法一:
[root@STCO6 tmp]# cat SKfile1.sh #!/bin/bash # declare -i sfile_sum=0 declare -i kfile_sum=0 for i in `ls /etc/rc.d/rc3.d | grep "^K"`;do echo "$i stop" let kfile_sum++ done for i in `ls /etc/rc.d/rc3.d | grep "^S"`;do echo "$i start" let sfile_sum++ done echo "S file is $sfile_sum" echo "K file is $kfile_sum" [root@STCO6 tmp]# chmod +x SKfile1.sh [root@STCO6 tmp]# ./SKfile1.sh K01smartd stop K02oddjobd stop K05wdaemon stop K10psacct stop K10saslauthd stop K15htcacheclean stop K15httpd stop K30spice-vdagentd stop K50dnsmasq stop K60nfs stop K61nfs-rdma stop K69rpcsvcgssd stop K73winbind stop K74ntpd stop K75ntpdate stop K75quota_nld stop K76ypbind stop K84wpa_supplicant stop K87restorecond stop K88sssd stop K89netconsole stop K89rdisc stop K92pppoe-server stop K95firstboot stop K95rdma stop K99rngd stop S01sysstat start S02lvm2-monitor start S08ip6tables start S08iptables start S10network start S11auditd start S11portreserve start S12rsyslog start S13cpuspeed start S13irqbalance start S13rpcbind start S15mdmonitor start S22messagebus start S23NetworkManager start S24nfslock start S24rpcgssd start S25blk-availability start S25cups start S25netfs start S26acpid start S26haldaemon start S26udev-post start S28autofs start S50bluetooth start S50kdump start S55sshd start S80postfix start S82abrt-ccpp start S82abrtd start S90crond start S95atd start S99certmonger start S99local start S file is 33 K file is 26
方法二:
[root@STCO6 tmp]# cat SKfile2.sh #!/bin/bash # ls /etc/rc.d/rc3.d/K*|awk ‘{printf "%s Stop \n", $1}‘|awk -F‘/‘ ‘{print $NF}‘ ls /etc/rc.d/rc3.d/S*|awk ‘{printf "%s Start \n", $1}‘|awk -F‘/‘ ‘{print $NF}‘ kfile_lines=`ls /etc/rc.d/rc3.d/K*|awk ‘{print NR}‘|tail -1` sfile_lines=`ls /etc/rc.d/rc3.d/S*|awk ‘{print NR}‘|tail -1` echo "Kfile lines is $kfile_lines" echo "Sfile lines is $sfile_lines" [root@STCO6 tmp]# chmod +x SKfile2.sh [root@STCO6 tmp]# bash -n SKfile2.sh [root@STCO6 tmp]# ./SKfile2.sh K01smartd Stop K02oddjobd Stop K05wdaemon Stop K10psacct Stop K10saslauthd Stop K15htcacheclean Stop K15httpd Stop K30spice-vdagentd Stop K50dnsmasq Stop K60nfs Stop K61nfs-rdma Stop K69rpcsvcgssd Stop K73winbind Stop K74ntpd Stop K75ntpdate Stop K75quota_nld Stop K76ypbind Stop K84wpa_supplicant Stop K87restorecond Stop K88sssd Stop K89netconsole Stop K89rdisc Stop K92pppoe-server Stop K95firstboot Stop K95rdma Stop K99rngd Stop S01sysstat Start S02lvm2-monitor Start S08ip6tables Start S08iptables Start S10network Start S11auditd Start S11portreserve Start S12rsyslog Start S13cpuspeed Start S13irqbalance Start S13rpcbind Start S15mdmonitor Start S22messagebus Start S23NetworkManager Start S24nfslock Start S24rpcgssd Start S25blk-availability Start S25cups Start S25netfs Start S26acpid Start S26haldaemon Start S26udev-post Start S28autofs Start S50bluetooth Start S50kdump Start S55sshd Start S80postfix Start S82abrt-ccpp Start S82abrtd Start S90crond Start S95atd Start S99certmonger Start S99local Start Kfile lines is 26 Sfile lines is 33
13、写一个脚本,完成以下功能
(1) 脚本能接受用户名作为参数;
(2) 计算此些用户的ID之和;
[root@STCO6 tmp]# cat usersum.sh #!/bin/bash # read -p "Please enter some users:" user if [ -z "$user" ] ; then echo "The username may not be empty. Please enter a valid username!" && exit fi for i in $user; do if ! id $i &> /dev/null; then echo "$i not exists" else let j=`id -u $i` let sum+=$j fi done echo "Sum is $sum!" [root@STCO6 tmp]# chmod +x usersum.sh [root@STCO6 tmp]# ./usersum.sh Please enter some users:testuser1 testuser2 testuser3 testsuer10 testuser11 testsuer10 not exists testuser11 not exists Sum is 1509!
14、写一个脚本
(1) 传递一些目录给此脚本;
(2) 逐个显示每个目录的所有一级文件或子目录的内容类型;
(3) 统计一共有多少个目录;且一共显示了多少个文件的内容类型;
[root@STCO6 tmp]# cat directory1.sh #!/bin/bash # declare -i directory=0 declare -i file=0 declare -i string_file=0 declare -i link_file=0 declare -i block_file=0 if [ $# -lt 1 ];then echo "Useage:directory1.sh directory|file ..." exit 1 else for j in $*;do if [ -f $j ];then echo "This file is file" exit 1 else for i in `ls $j`;do cd $j if [ -f $i ];then echo -e "$i is file." let file++ elif [ -d $i ];then echo -e "$i is directory." let directory++ elif [ -c $i ];then echo "$i is string file." let string_file++ elif [ -L $i ];then echo "$i is link file." let link_file++ elif [ -b $i ];then echo "$i is block file." let block_file++ else echo "Unknow file." exit 2 fi done fi done fi echo "directory file total:$directory" echo "file total:$file" echo "String file total:$string_file" echo "link file total:$link_file" echo "block file total:$block_file" [root@STCO6 tmp]# chmod +x directory1.sh [root@STCO6 tmp]# bash -n directory1.sh [root@STCO6 tmp]# ./directory1.sh /etc abrt is directory. acpi is directory. adjtime is file. aliases is file. aliases.db is file. alsa is directory. alternatives is directory. anacrontab is file. anthy-conf is file. asound.conf is file. at.deny is file. audisp is directory. audit is directory. autofs.conf is file. autofs_ldap_auth.conf is file. auto.master is file. auto.misc is file. auto.net is file. auto.smb is file. avahi is directory. bash_completion.d is directory. bashrc is file. blkid is directory. bluetooth is directory. bonobo-activation is directory. cas.conf is file. centos-release is file. certmonger is directory. chkconfig.d is directory. ConsoleKit is directory. cron.d is directory. cron.daily is directory. cron.deny is file. cron.hourly is directory. cron.monthly is directory. crontab is file. cron.weekly is directory. crypttab is file. csh.cshrc is file. csh.login is file. cups is directory. dbus-1 is directory. default is directory. depmod.d is directory. dhcp is directory. DIR_COLORS is file. DIR_COLORS.256color is file. DIR_COLORS.lightbgcolor is file. dnsmasq.conf is file. dnsmasq.d is directory. dracut.conf is file. dracut.conf.d is directory. drirc is file. enscript.cfg is file. environment is file. ethers is file. exports is file. favicon.png is file. festival is directory. filesystems is file. firefox is directory. fonts is directory. foomatic is directory. fprintd.conf is file. fstab is file. gai.conf is file. gconf is directory. gcrypt is directory. gdm is directory. ghostscript is directory. gnome-vfs-2.0 is directory. gnupg is directory. group is file. group- is file. grub.conf is file. gshadow is file. gshadow- is file. gssapi_mech.conf is file. gtk-2.0 is directory. hal is directory. host.conf is file. hosts is file. hosts.allow is file. hosts.deny is file. hp is directory. httpd is directory. idmapd.conf is file. init is directory. init.conf is file. init.d is directory. inittab is file. inputrc is file. ipa is directory. iproute2 is directory. issue is file. issue.net is file. java is directory. jvm is directory. jvm-commmon is directory. kde is directory. kde4rc is file. kderc is file. kdump-adv-conf is directory. kdump.conf is file. krb5.conf is file. latrace.conf is file. latrace.d is directory. ld.so.cache is file. ld.so.conf is file. ld.so.conf.d is directory. libaudit.conf is file. libnl is directory. libreport is directory. libuser.conf is file. localtime is file. login.defs is file. logrotate.conf is file. logrotate.d is directory. lsb-release is file. lsb-release.d is directory. ltrace.conf is file. lvm is directory. magic is file. mailcap is file. mail.rc is file. makedev.d is directory. man.config is file. maven is directory. mime.types is file. mke2fs.conf is file. modprobe.d is directory. motd is file. mtab is file. mtools.conf is file. my.cnf is file. nanorc is file. netconfig is file. NetworkManager is directory. networks is file. nfsmount.conf is file. nsswitch.conf is file. ntp is directory. ntp.conf is file. obex-data-server is directory. oddjob is directory. oddjobd.conf is file. oddjobd.conf.d is directory. openldap is directory. opt is directory. PackageKit is directory. pam.d is directory. pango is directory. passwd is file. passwd- is file. pbm2ppa.conf is file. pcmcia is directory. pinforc is file. pkcs11 is directory. pki is directory. plymouth is directory. pm is directory. pm-utils-hd-apm-restore.conf is file. pnm2ppa.conf is file. polkit-1 is directory. popt.d is directory. portreserve is directory. postfix is directory. ppp is directory. prelink.cache is file. prelink.conf is file. prelink.conf.d is directory. printcap is file. profile is file. profile.d is directory. protocols is file. pulse is directory. purple is directory. quotagrpadmins is file. quotatab is file. rc is file. rc0.d is directory. rc1.d is directory. rc2.d is directory. rc3.d is directory. rc4.d is directory. rc5.d is directory. rc6.d is directory. rc.d is directory. rc.local is file. rc.sysinit is file. rdma is directory. readahead.conf is file. redhat-lsb is directory. redhat-release is file. request-key.conf is file. request-key.d is directory. resolv.conf is file. rpc is file. rpm is directory. rsyslog.conf is file. rsyslog.d is directory. rwtab is file. rwtab.d is directory. samba is directory. sane.d is directory. sasl2 is directory. scl is directory. screenrc is file. securetty is file. security is directory. selinux is directory. services is file. sestatus.conf is file. setuptool.d is directory. sgml is directory. shadow is file. shadow- is file. shells is file. skel is directory. smartd.conf is file. sos.conf is file. sound is directory. ssh is directory. ssl is directory. sssd is directory. statetab is file. statetab.d is directory. sudo.conf is file. sudoers is file. sudoers.d is directory. sudo-ldap.conf is file. sysconfig is directory. sysctl.conf is file. sysctl.d is directory. system-release is file. system-release-cpe is file. terminfo is directory. Trolltech.conf is file. udev is directory. updatedb.conf is file. vimrc is file. virc is file. warnquota.conf is file. wgetrc is file. wpa_supplicant is directory. X11 is directory. xdg is directory. xinetd.d is directory. xml is directory. yp.conf is file. yum is directory. yum.conf is file. yum.repos.d is directory. zlogin is file. zlogout is file. zprofile is file. zshenv is file. zshrc is file. directory file total:123 file total:135 String file total:0 link file total:0 block file total:0
15、写一个脚本
通过命令行传递一个参数给脚本,参数为用户名
如果用户的id号大于等于500,则显示此用户为普通用户;
[root@STCO6 tmp]# cat user.sh #!/bin/bash # [ $# -ne 1 ] && echo "Please enter one user" && exit ! id $1 &> /dev/null && echo "User not exist" && exit let a=`id -u $1` if [ $a -ge 500 ]; then echo "$1 is common user." else echo "$1 is system user." fi [root@STCO6 tmp]# chmod +x user.sh [root@STCO6 tmp]# bash -n user.sh [root@STCO6 tmp]# ./user.sh Please enter one user [root@STCO6 tmp]# ./user.sh root root is system user. [root@STCO6 tmp]# ./user.sh user1 user1 is common user.
16、写一个脚本
(1) 添加10用户user1-user10;密码同用户名;
(2) 用户不存在时才添加;存在时则跳过;
(3) 最后显示本次共添加了多少用户;
[root@STCO6 tmp]# cat useradd.sh #!/bin/bash # for i in {1..10}; do if id user$i &> /dev/null ;then echo "user$i exists." continue 3 else useradd user$i if [ $? -eq 0 ]; then echo "user$i" | passwd --stdin user$i &> /dev/null echo "useradd user$i finished." let sum++ fi fi done echo " useradd $sum user " [root@STCO6 tmp]# chmod +x useradd.sh [root@STCO6 tmp]# bash -n useradd.sh [root@STCO6 tmp]# ./useradd.sh user1 exists. useradd user2 finished. useradd user3 finished. useradd user4 finished. useradd user5 finished. useradd user6 finished. useradd user7 finished. useradd user8 finished. useradd user9 finished. user10 exists. useradd 8 user
17、写一脚本,用ping命令测试172.16.250.20-172.16.250.100以内有哪些主机在线,将在线的显示出来;
[root@STCO6 ~]# cat /tmp/ping.sh #!/bin/bash # ip_address=‘172.16.250‘ for i in {20..100};do ping -c 5 -w 5 ${ip_address}.${i} &> /dev/null if [ $? -eq 0 ]; then echo -e "\033[32m ${ip_address}.${i} \033[0m" fi done
18、打印九九乘法表;
方法一:
[root@STCO6 tmp]# cat 99_1.sh #!/bin/bash # for i in {1..9}; do for j in $(seq 1 $i); do echo -e -n "${i}X${j}=$[$i*$j]\t" done echo done [root@STCO6 tmp]# chmod +x 99_1.sh [root@STCO6 tmp]# bash -n 99_1.sh [root@STCO6 tmp]# ./99_1.sh 1X1=1 2X1=2 2X2=4 3X1=3 3X2=6 3X3=9 4X1=4 4X2=8 4X3=12 4X4=16 5X1=5 5X2=10 5X3=15 5X4=20 5X5=25 6X1=6 6X2=12 6X3=18 6X4=24 6X5=30 6X6=36 7X1=7 7X2=14 7X3=21 7X4=28 7X5=35 7X6=42 7X7=49 8X1=8 8X2=16 8X3=24 8X4=32 8X5=40 8X6=48 8X7=56 8X8=64 9X1=9 9X2=18 9X3=27 9X4=36 9X5=45 9X6=54 9X7=63 9X8=72 9X9=81
方法二:
[root@STCO6 tmp]# cat 99_2.sh #!/bin/bash # declare -i i=1 declare -i j=1 while [ $i -le 9 ]; do while [ $j -le $i ]; do echo -e -n "${i}X${j}=$[$i*$j]\t" let j++ done echo let i++ let j=1 done [root@STCO6 tmp]# chmod +x 99_2.sh [root@STCO6 tmp]# bash -n 99_2.sh [root@STCO6 tmp]# ./99_2.sh 1X1=1 2X1=2 2X2=4 3X1=3 3X2=6 3X3=9 4X1=4 4X2=8 4X3=12 4X4=16 5X1=5 5X2=10 5X3=15 5X4=20 5X5=25 6X1=6 6X2=12 6X3=18 6X4=24 6X5=30 6X6=36 7X1=7 7X2=14 7X3=21 7X4=28 7X5=35 7X6=42 7X7=49 8X1=8 8X2=16 8X3=24 8X4=32 8X5=40 8X6=48 8X7=56 8X8=64 9X1=9 9X2=18 9X3=27 9X4=36 9X5=45 9X6=54 9X7=63 9X8=72 9X9=81
方法三:
[root@STCO6 tmp]# cat 99_3.sh #!/bin/bash # declare -i i=1 declare -i j=1 until [ $i -gt 9 ]; do until [ $j -gt $i ]; do echo -n -e "${i}X${j}=$[$i*$j]\t" let j++ done echo let i++ let j=1 done [root@STCO6 tmp]# chmod +x 99_3.sh [root@STCO6 tmp]# bash -n 99_3.sh [root@STCO6 tmp]# ./99_3.sh 1X1=1 2X1=2 2X2=4 3X1=3 3X2=6 3X3=9 4X1=4 4X2=8 4X3=12 4X4=16 5X1=5 5X2=10 5X3=15 5X4=20 5X5=25 6X1=6 6X2=12 6X3=18 6X4=24 6X5=30 6X6=36 7X1=7 7X2=14 7X3=21 7X4=28 7X5=35 7X6=42 7X7=49 8X1=8 8X2=16 8X3=24 8X4=32 8X5=40 8X6=48 8X7=56 8X8=64 9X1=9 9X2=18 9X3=27 9X4=36 9X5=45 9X6=54 9X7=63 9X8=72 9X9=81
标签:第8周作业
原文地址:http://257023.blog.51cto.com/247023/1857957