理工大嵌入式操作系统实验报告之Shell编程和Makefile文件

知识共享许可协议 版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons

一、实验目的和要求
1 了解什么是脚本
2 掌握shell编程方法
3 掌握makefile的编写规则

二、实验内容和原理
1 编写一个Shell脚本,要求:显示当前目录的所有内容,并统计可执行文件(.sh)的数量,将统计结果输入到指定的文件当中;

2 编写一个Shell脚本,要求:
2.1 在屏幕上显示一行提示信息
2.2 读入一行命令
2.3 判断此命令是否为“exit”,若是则退出
2.4 如果不是,分析并执行这行命令

3 假定一个程序由以下5个文件组成,其源代码如下,请编写一个Makefile文件,并运行。
文件1:main.c
#include “mytool1.h”
#include “mytool2.h”
int main()
{ mytool1_print(“hello mytool1!”);
mytool2_print(“hello mytool2!”);
return 0;
}

文件2:mytool1.c
#include “mytool1.h”
#include <stdio.h>
void mytool1_print(char *print_str)
{
printf("This is mytool1 print : %s ",print_str);
}

文件3:mytool1.h
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H
void mytool1_print(char *print_str);
#endif

文件4:mytool2.c
#include “mytool2.h”
#include <stdio.h>
void mytool2_print(char *print_str) {
printf("This is mytool2 print : %s ",print_str);
}

文件5:mytool2.h
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H
void mytool2_print(char *print_str);
#endif

三、主要仪器设备 PC机、装有Linux操作系统的虚拟机
四、 操作方法与实验步骤
1 #!/bin/bash
ls sh
find . –name “
.sh” | wc -|>>1.txt

2 #!/bin/bash
echo “Enter a order!”
read name
$name
3 appexam: main.o mytool1o mytool2.o
main.o:main.c mytool1.h mytool2.h
mytool1.o:mytool1.c mytool1.h
mytool2.o:mytool2.c mytool2.h
clean:
rm –f *.o
五、实验数据和记录
1运行脚本执行命令
vi 1.sh
./1.sh
cat 1.txt
2 运行之后输入内容被2.sh脚本读入以命令输出
在这里插入图片描述
六、实验结果与分析

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44611644/article/details/95068820