V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
superPershing
V2EX  ›  编程

Python 脚本能完全代替 shell 脚本的工作吗?

  •  
  •   superPershing · Apr 24, 2017 · 9784 views
    This topic created in 3290 days ago, the information mentioned may be changed or developed.

    shell 的不少工作都能由 Python 来代替(个人愚见。。),那么在日常开发中,在 linux 下能完全用 Python 代替 shell 编程吗?请各位大佬来打击我的说法,让菜鸟开阔一下眼界。

    25 replies    2017-04-25 09:46:37 +08:00
    Finest
        1
    Finest  
       Apr 24, 2017
    可以
    superPershing
        2
    superPershing  
    OP
       Apr 24, 2017
    @hand515 那是不是说在某种程度上没有学 shell 的必要了?
    jtsai
        3
    jtsai  
       Apr 24, 2017   ❤️ 1
    @superPershing 学 shell 是学 shell 的思想,怎么跟 liunx 打交道。不学 shell 你也不知道怎么用 Python 跟 linux 打交道
    holyghost
        4
    holyghost  
       Apr 24, 2017   ❤️ 1
    @superPershing 当然

    以前是 perl 在某种程度上承担了替代 shell 脚本的功能(当然 perl 自己说初衷是为了搞死 awk 和 sed ),现在是 python
    BOYPT
        5
    BOYPT  
       Apr 24, 2017
    (这就是你不学习 shell 的借口嘛!
    FunctionOne
        6
    FunctionOne  
       Apr 24, 2017
    #! /usr/bin/env python

    这个……
    FunctionOne
        7
    FunctionOne  
       Apr 24, 2017
    这个谁来解释呢?
    SuperMild
        8
    SuperMild  
       Apr 24, 2017   ❤️ 1
    不仅 Python ,甚至用 Java 都可以,有人这样做了:
    https://www.teamten.com/lawrence/writings/java-for-everything.html
    bozong
        9
    bozong  
       Apr 24, 2017
    Finest
        10
    Finest  
       Apr 24, 2017
    @superPershing

    不学 shell ,你在 linux 下的工作效率会下降很多
    heiybb
        11
    heiybb  
       Apr 24, 2017 via Android
    @bozong 这个回复意义何在…
    jinghangdayunhe
        12
    jinghangdayunhe  
       Apr 24, 2017
    @bozong 啥好东西?
    imn1
        13
    imn1  
       Apr 24, 2017
    “完全”是不能的,除非你想降低效率

    例如
    cat text.txt

    ls ../*.txt

    python 如何提高效率
    tammy
        14
    tammy  
       Apr 24, 2017
    我想说 python shell 也是 shell 啊,楼主你说的是 posix shell?
    bozong
        15
    bozong  
       Apr 24, 2017
    @heiybb #11
    @hand515 #10 Ctrl+V 按快了。 也删不了。
    kmyzzy
        16
    kmyzzy  
       Apr 24, 2017   ❤️ 1
    试试 xonsh ,支持 shell 命令,也支持 python 语法
    Marfal
        17
    Marfal  
       Apr 24, 2017
    @bozong #15 微博图床的弊端:不能删 hhh
    lucifer9
        18
    lucifer9  
       Apr 24, 2017
    绝对可以吧,如果有不行的,请呼叫 os.system
    geelaw
        19
    geelaw  
       Apr 24, 2017
    这俩玩意儿难道不是平凡地互相归约么?互相调用并不困难吧
    dacapoday
        20
    dacapoday  
       Apr 24, 2017   ❤️ 2
    更完善的说是用 ipython 代替 shell ,而且 ipython 中 !开头的语句当做 shell 执行,从而兼顾 shell 便利和 python 的强大。
    CQCQCQ
        21
    CQCQCQ  
       Apr 24, 2017 via iPhone
    集多不压身!我就想问一下大家三个字母的 top 快还是 import os.system xxxxx 快?
    fisher335
        22
    fisher335  
       Apr 24, 2017 via iPhone
    你用 python 这个 netstat 命令嘛!
    mingyun
        23
    mingyun  
       Apr 24, 2017
    crontab 怎么替代
    privil
        24
    privil  
       Apr 25, 2017 via iPhone
    让 shell 的归 shell , python 的归 python 。这样或许是极好的
    mN71eOOprFyMsnPx
        25
    mN71eOOprFyMsnPx  
       Apr 25, 2017   ❤️ 1
    Python 完全代替 Shell 脚本是没问题的。

    但是, Python 不能代替日常使用的 Shell 命令。

    这点要搞清楚。一定要记住,别用 Shell 命令写较长的脚本就是。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5647 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 89ms · UTC 08:23 · PVG 16:23 · LAX 01:23 · JFK 04:23
    ♥ Do have faith in what you're doing.