From de16f53f0577f1945dc5832ad03db2ab6fb90285 Mon Sep 17 00:00:00 2001 From: mayx Date: Sun, 27 Mar 2022 15:07:44 +0000 Subject: 更新 _posts/2022-03-27-radio.md, _posts/2019-04-24-shell.md, _posts/2021-05-07-ssh.md, _posts/2022-03-12-alpine.md, _posts/2022-02-15-termux.md --- _posts/2019-04-24-shell.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to '_posts/2019-04-24-shell.md') diff --git a/_posts/2019-04-24-shell.md b/_posts/2019-04-24-shell.md index 04e09c2..d42acb3 100644 --- a/_posts/2019-04-24-shell.md +++ b/_posts/2019-04-24-shell.md @@ -9,13 +9,13 @@ tags: [Shell, 编程] Shell 脚本很棒,你可以非常轻松地写出有用的东西来。甚至像是下面这个傻瓜式的命令: -``` +```shell # 用含有 Go 的词汇起名字: $ grep -i ^go /usr/share/dict/* | cut -d: -f2 | sort -R | head -n1 goldfish ``` 如果用其他编程语言,就需要花费更多的脑力,用多行代码实现,比如用 Ruby 的话: -``` +```ruby puts(Dir['/usr/share/dict/*-english'].map do |f| File.open(f) .readlines @@ -25,7 +25,7 @@ end.flatten.sample.chomp) Ruby 版本的代码虽然不是那么长,也并不复杂。但是 shell 版是如此简单,我甚至不用实际测试就可以确保它是正确的。而 Ruby 版的我就没法确定它不会出错了,必须得测试一下。而且它要长一倍,看起来也更复杂。 这就是人们使用 Shell 脚本的原因,它简单却实用。下面是另一个例子: -``` +```shell curl https://nl.wikipedia.org/wiki/Lijst_van_Nederlandse_gemeenten | grep '^