这并不能完全回答您的问题,但希望能为您提供一个开始。
bash
has a script
命令。这是一个足够令人困惑的名字,是吗?基本上,script
是一个交互式终端记录器。既然没有whatis
它的入口,这里是开始man
page:
$ man script | head -n 17 | sed '/^$/d'
SCRIPT(1) User Commands SCRIPT(1)
NAME
script - make typescript of terminal session
SYNOPSIS
script [options] [file]
DESCRIPTION
script makes a typescript of everything displayed on your terminal. It
is useful for students who need a hardcopy record of an interactive
session as proof of an assignment, as the typescript file can be
printed out later with lpr(1).
If the argument file is given, script saves the dialogue in this file.
If no filename is given, the dialogue is saved in the file typescript.
让我给您举一个例子,然后我将向您展示我使用此命令执行的操作的详细信息,并介绍如何使用此命令来完成任务。我从我的 Cygwin 终端运行这个。
$ script
Script started, file is typescript
$ pwd
/home/me
$ # This is a comment
$ ping google.com
PING google.com (172.217.12.206): 56 data bytes
64 bytes from 172.217.12.206: icmp_seq=0 ttl=51 time=68 ms
64 bytes from 172.217.12.206: icmp_seq=1 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=2 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=3 ttl=51 time=67 ms
64 bytes from 172.217.12.206: icmp_seq=4 ttl=51 time=68 ms
64 bytes from 172.217.12.206: icmp_seq=5 ttl=51 time=67 ms
----google.com PING Statistics----
6 packets transmitted, 6 packets received, 0.0% packet loss
round-trip (ms) min/avg/max/med = 67/67/68/67
$ # End of Comment
$ cd /
$ pwd
/
$ exit
exit
Script done, file is typescript
$ pwd
/home/me
现在我们将查看生成的文件。不要尝试head
or cat
,因为您不会看到我们遇到的问题(或功能,如果您想要“^C”)。
这是前几行vim typescript
您将看到转义和控制序列。这些可以删除(参见清理输出下面的部分。)
现在,您可以设置一个doxygen
过滤器,有点像描述的那样here http://rickfoosusa.blogspot.com/2011/08/howto-have-doxygen-support-bash-script.html
(就在这里,因为链接可能会失效)
Doxygen 不支持 bash 脚本文件。虽然这可能会让
感觉,不支持它们(定义一个 bash 脚本文件
函数和变量),总是有一些在一个
应该进入文档的源代码树。
添加脚本文件而不更改它们是最简单的,因此
doxygen 输入过滤器。输入过滤器与命令行配合得很好
sed 或 awk 命令,所以我们将在这里做一个简单的命令,让您添加
Doxygen 命令以 ## 开头的行。
在 Doxyfile 中编辑这些行:
FILE_PATTERNS = *.sh *.awk
INPUT_FILTER = "sed -e 's|##|//!|'"
FILTER_SOURCE_FILES = YES
在每个文件的顶部添加简短说明:
## functions for OpenEmbedded, and Jenkins -*- shell-script -*-.
## @author rickfoosusa
## @file
一般来说,任何与#
评论可以,但对于语言
通过使用像 asm4doxy.pl 这样的过滤器,你可以获得更多的文档http://rudy.mif.pg.gda.pl/~bogdro/inne/asm4doxy.txt http://rudy.mif.pg.gda.pl/~bogdro/inne/asm4doxy.txt
希望这能为您指明正确的方向。我希望能回来并充实一下它。
清理输出
我使用以下两个文件来摆脱转义序列,一个perl
script
#!/usr/bin/perl
#
##############################################################################
# Takes escape and control sequences out of the `script` command's output
#
# @file output_scrubbed_script.pl
#
# Okay, I found this all over the internet, it's just my favorite.
# This removes all unwanted junk (control characters, etc) from the output
# of the Linux script command.
# It's imperfect. It struggles with vim, and it doesn't do too well with up
# arrows and tab completion, but I can usually at least see and understand
# what I did.
#
##############################################################################
while (<>)
{
s/ \e[ #%()*+\-.\/]. |
\r | # Remove extra carriage returns also
(?:\e\[|\x9b) [ -?]* [@-~] | # CSI ... Cmd
(?:\e\]|\x9d) .*? (?:\e\\|[\a\x9c]) | # OSC ... (ST|BEL)
(?:\e[P^_]|[\x90\x9e\x9f]) .*? (?:\e\\|\x9c) | # (DCS|PM|APC) ... ST
\e.|[\x80-\x9f] //xg;
1 while s/[^\b][\b]//g; #remove all non-backspace followed by backspace
print;
}
and a bash
script
#!/bin/bash
#
##############################################################################
# Runs the clean-up
#
# @file script_scrubber.sh
# @author bballdave025
#
# See the usage variable
#
##############################################################################
usage="Usage is:\n > script_scrubber.sh <unscrubbed-file> "\
"[<alternate-filename>]\n"\
"If no <alternate-filename> argument is given, the <unscrubbed-file> \n"\
"will be cleaned in place.\n\n"\
"This script takes the output of the Linux script command and cleans"\
"control characters and other unwanted artifacts."\
"It uses output_scrubbed_text.pl\n"
scrubber_path="$HOME"
scrubber_location="${scrubber_path}/output_scrubbed_text.pl"
if [[ ! -f "${scrubber_location}" ]]; then
echo -e "Fatal error! ${scrubber_location} does not exist."
exit 1
fi #endof: if [[ -f "${location}/output_scrubbed_text.pl" ]]
if [[ ! -x "${scrubber_location}" ]]; then
chmod +x "${scrubber_location}"
fi #endof: if [[ ! -x "${scrubber_location}" ]]
if [[ $# -eq 0 ]]; then
echo "No argument given."
echo -e "${usage}"
exit 2
elif [[ $# -eq 1 ]]; then
if [[ $1 == "--help" ]]; then
echo -e "${usage}"
exit 0
else
"${scrubber_location}" $1 > tmp && mv tmp $1
fi #endof: if [[ $1 -eq "--help" ]]
elif [[ $# -eq 2 ]]; then
"${scrubber_location}" $1 > $2
else
echo "More than two arguments given."
echo -e "${usage}"
fi #endof: if [[ $# -eq <0,1,2,else> ]