# 自动生成bitbook的summary文件

```bash
#!/bin/bash
# set -ex
root=$1
if [ -z "$root" ];then
root="./"
fi

cd $root

ignore="! -iname "README.MD" ! -iname "SUMMARY.MD" ! -iname "_SUMMARY.MD" ! -path "./.git" ! -path "./node_modules""

getspcae(){
    tab=""
    local count=`expr $1 - 2`
    if [ "${count}" -le 0 ]; then return;fi

    for a in `seq $count`
    do
     tab=${tab}"  "
    done
    echo "${tab}"
}

writeline(){
    fpath=$1
    depth=$2
    title=`head -1 $fpath`
    title=${title:1}
    #将开头的#号去掉
    title=${title/#\#/}
    #去掉开头空格
    title=${title/# /}
    #去掉开头的点
    fpath=${fpath:1}

    tab=`getspcae $depth`

    result="${result}${tab}* [${title}](${fpath})\n"
}
getnode(){
    title=$1
    depth=$2
    title=${title:2}
    title=${title#*/}
    tab=`getspcae $depth`

    echo "${tab}* ${title}"
}
dive(){
    local dirs=$1
    if [ -z "$dirs" ]; then return;fi


    local depth=$2
    local node=$3
    local nextdepth=`expr $2 + 1`
    #写节点
    if [ -n "$node" ];then
      result="${result}${node}\n"
    fi

    for dir in ${dirs[@]}
    do
        if [ -d "${dir}" ];then
          nextnode=`getnode "${dir}" ${nextdepth}`
        dive "`find ${dir} -maxdepth 1  -mindepth 1 \( -iname "*.md" -or -type d \)`" $nextdepth "${nextnode}"
        else
          writeline "${dir}" ${nextdepth}
        fi
    done
}

result=""

dive "`find . -maxdepth 1  -mindepth 1 \( -iname "*.md" -or -type d \) ${ignore}`" 1

#写文件
echo generate SUMMARY.md
echo "${result}" > ${root}/SUMMARY.md
echo finish
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.rizon.top/jiao-ben/shell/sheng-cheng-gitbooksummary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
