V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
FatGhosta
V2EX  ›  Linux

什么样的 shell 脚本可以称为写得好的脚本?

  •  3
     
  •   FatGhosta · 2015-07-21 17:55:48 +08:00 · 3794 次点击
    这是一个创建于 3173 天前的主题,其中的信息可能已经有所发展或是发生改变。
    13 条回复    2015-07-30 22:41:12 +08:00
    echo1937
        1
    echo1937  
       2015-07-21 17:59:13 +08:00
    写1个shell脚本的时间,可以写3个py脚本,一个2.6.6, 一个2.7.5,一个3.4.3


    正经回答,稍微大点的shell脚本写着实在是费劲。
    VmuTargh
        2
    VmuTargh  
       2015-07-21 18:00:51 +08:00
    Netbeans
    chuxiwen
        3
    chuxiwen  
       2015-07-21 21:14:03 +08:00 via iPad   ❤️ 3
    都 shell 了。能用就行吧。如果要垮平台用的话,尽量做到 bourne shell compatible 吧。最后祝你好运。

    下边是 google 的 guildline
    https://google-styleguide.googlecode.com/svn/trunk/shell.xml
    frankzeng
        4
    frankzeng  
       2015-07-21 21:23:09 +08:00
    简单一点还行,复杂逻辑的用shell不太合适。
    Dongdong36
        5
    Dongdong36  
       2015-07-21 21:36:47 +08:00
    写注释 写注释 写注释
    staticor
        6
    staticor  
       2015-07-21 22:22:37 +08:00
    comment, log.
    neo2015
        7
    neo2015  
       2015-07-22 09:10:37 +08:00
    当年被迫在openwrt写shell cgi,感觉心好累
    bramblex
        8
    bramblex  
       2015-07-22 10:48:54 +08:00
    楼上写python的跟我把下面这行shellscript用python实现下

    echo `who | awk '{print $1}' | sort | uniq` | sed 's/ /, /g' > file.txt

    shellscript最强大的功能是组合连接各个命令行工具,你完全可以增加命令行工具来配合shellscript编写。如果你觉得shellscript非常麻烦,那么说明你肯定用错了场景。比如你要拿shellscript做大量运算,那绝对是坑爹的……
    bramblex
        9
    bramblex  
       2015-07-22 10:51:34 +08:00
    同时,即便是shellscript,也是可以进行良好的模块化的。shellscript真正能写的人其实不是很多,大部分说自己会写shellscript的都只是会逐行罗列几个命令而已
    FatGhosta
        10
    FatGhosta  
    OP
       2015-07-22 20:05:19 +08:00
    julyclyde
        11
    julyclyde  
       2015-07-22 21:40:47 +08:00
    换到另一个发行版的白板机器还能直接运行无需修改的,就是好脚本
    jack139
        12
    jack139  
       2015-07-23 13:03:09 +08:00
    除了系统管理脚本,不建议用shell,python是个不错的选择
    lilydjwg
        13
    lilydjwg  
       2015-07-30 22:41:12 +08:00
    @julyclyde 这样的脚本恐怕除了 configure 之外很少见呢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5174 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 09:29 · PVG 17:29 · LAX 02:29 · JFK 05:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.