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.自己整理分文件编译,改之前写过的代码

相关推荐
Julien200440 分钟前
管理 Ansible 配置文件
linux·运维·服务器·ssh·学习方法
MicrosoftCloud1 小时前
性能排查 01|free 显示内存用了 90% 就是快满了吗?buff/cache 与 available 一次讲清
linux·运维·内存·free·buff/cache
xiaoye-duck2 小时前
《Linux 网络编程》深入理解 epoll(下):epoll 实战开发与 LT/ET 触发模式深度剖析
linux·网络
峥无2 小时前
Linux线程深度剖析:轻量级进程、虚拟内存分页、进程线程资源对比
linux·运维·mmap
北风催呀催3 小时前
HuggingFace下载镜像加速技巧
linux·huggingface
MicrosoftCloud4 小时前
性能排查 02|vmstat、iostat、mpstat、sar 怎么读?性能四件套的分工与判读阈值
linux·ubuntu·vmstat·性能监控·iostat·sysstat
AR-26710-4 小时前
Linux Day16——日志
linux·运维
小HANN4 小时前
华为云企业网站上云实战|从零搭建高可用WordPress(ECS+RDS+ELB+弹性伸缩+云监控全流程落地)
linux·运维·服务器·经验分享
susplus5 小时前
【IMX6ULL Linux系统移植】SD卡分区 | uboot详解
linux·arm·u-boot