惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
量子位
G
Google Developers Blog
J
Java Code Geeks
N
Netflix TechBlog - Medium
博客园 - 聂微东
宝玉的分享
宝玉的分享
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
雷峰网
雷峰网
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss

Bash

Linux bash 脚本监控和重启一个守护进程 有个脚本代码的问题 Bash Script 代码比较,你认为哪个更加容易理解? 有使用 kitty 当日常终端的老哥吗? 在输入命令时,自动调用 fzf 进行模糊匹配 使用 shell 的 bash -c "functions"时,是不是所有相关的函数都得声明出来? shell 比较浮点数大小的问题,顺便吐槽以下 shell bash-completor:声明式编写 Bash 补全脚本 sudo 改用 pkexec 的问题 sed 如何查找替换反斜杠 lobash 发布 v0.5.0 版本 为什么这样写无法连接(join)数组各项? 如何使用 awk 打印 nginx 404 日志的目录 请教一下,怎么把向终端输入的内容重定向一份到文件? 请教一下 shell 里使用 jq 处理 json 应该怎么写 求一个 wsl2 ubuntu20.04 的默认 /etc/bash.bashrc 如何让 bash 的补全 popup 显示 如何去除 Bash variable expansion 后加的单引号? 初学者写了个 bash 脚本,求大佬点评 tar 使用管道的困惑 如何获取命令标准输出到变量里并保留颜色?或者能不能一边输出一边赋值或判断。 请问如何在 alias 命令里传递参数? Bash 下如何优雅地临时在后台运行程序并易于管理? shell tr -cd 匹配字符串问题 shell 中的 import 能不能支持 as 或 alias 类似功能 Shell 多个文本间隔追加的方法 生产服务器集群被黑了,帮看看这个脚本 如何实现一个符合规范的 shell? 请教下如何检测文件是否存在 bash 里面有 io 多路复用吗?
闲的蛋疼,用 shell 写了个拓扑排序。。。
aheadlead · 2020-04-25 · via Bash
#!/usr/bin/env bash

if graph="$(mktemp -d)" || { echo failed; exit 2; } then
    trap 'rm -rf "${graph}"' exit
fi

while read start end; do
    mkdir -p "${graph}/${end}/${start}" "${graph}/${start}"
done

while [[ $(ls -1 "${graph}" | wc -l) -gt 0 ]]; do
    for u in ${graph}/*; do
        [[ $(ls -1 "${u}" | wc -l) -eq 0 ]] && { echo "$(basename ${u})"; break; }
    done | {
        read pop || { echo cylic; exit 1; }

        echo "${pop}"
        rmdir "${graph}/${pop}"

        for v in ${graph}/*; do
            [[ -d "${v}/${pop}" ]] && rmdir "${v}/${pop}"
        done
    }
done

大家看看写得对吗?


附赠输入输出:

CSCI-E-50a  CSCI-E-50b
CSCI-E-50b  CSCI-E-160
CSCI-E-160  CSCI-E-162
CSCI-E-50b  CSCI-E-119
CSCI-E-119  CSCI-E-215
CSCI-E-119  CSCI-E-124
CSCI-E-50b  MATH-E-104
MATH-E-10   CSCI-E-119
MATH-E-10   MATH-E-104
MATH-E-104  CSCI-E-124
CSCI-E-50a
CSCI-E-50b
CSCI-E-160
CSCI-E-162
MATH-E-10
CSCI-E-119
CSCI-E-215
MATH-E-104
CSCI-E-124

玩得开心~