6.26作业

1.整理思维导图

2.统计家目录下.c文件的个数

bash 复制代码
ls ~/*.c | wc -l

3.终端输入一个.sh文件,判断文件是否由可执行权限,如果有可执行权限运行脚本,没有可执行权限添加可执行权限后,再运行脚本

bash 复制代码
#!/bin/bash
read -p "请输入一个.sh文件:" file
if [ -x "$file" ]
then
	bash $file
else
	chmod u+x $file
	bash $file
fi

4.写一个函数,输出当前用户uid和gid,并使用变量接收结果

bash 复制代码
#!/bin/bash 
function fun()
{
  echo `id -u`
  echo `id -g`
}
ret=`fun`
echo $ret

5.终端输入年月,判断该月有多少天,考虑闰平年的情况

bash 复制代码
#!/bin/bash
read -p "请输入年:" year
read -p "请输入月:" month
case $month in 
	2)
		if [ $((year%4)) -eq 0 ] && [ $((year%100)) -ne 0 ] || [ $((year%400)) -eq 0 ]
		then
			echo 29天
		else
			echo 28天
		fi
	    ;;
	4|6|9|11)
		echo 30天
		;;
	1|3|5|7|8|10|12)
		echo 31天
		;;
	*)
		echo error
esac	

6.使用for循环,输出九九乘法表( printf "%d * %d = %d" i j $((i*j)) )

bash 复制代码
#!/bin/bash
for i in {1..9}
do
	for ((j=1;j<=i;j++))
	do
		echo -ne  "$j×$i=$(($j*$i))\t"
	done
	echo
done

7.使用for循环,找到家目录下的所有.c文件,如果文件有内容编译该文件,如果文件中没有内容,删除文件

bash 复制代码
#!/bin/bash
for file in `ls ~/*.c`
do
	if [ -s $file ]
	then
		gcc $file
	else
		rm $file
	fi
done

8.自己整理分文件编译,改之前写过的代码

相关推荐
CYRUS_STUDIO17 小时前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
熊猫李19 小时前
rootfs-根文件系统详解
linux
dessler21 小时前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
泽泽爱旅行21 小时前
awk 语法解析-前端学习
linux·前端
轻松Ai享生活2 天前
5 节课深入学习Linux Cgroups
linux
christine-rr2 天前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神5552 天前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆2 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
乌萨奇也要立志学C++2 天前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
獭.獭.2 天前
Linux -- 信号【上】
linux·运维·服务器