superPershing
V2EX  ›  编程

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

  •  
  •   superPershing · Apr 24, 2017 · 10292 views
    This topic created in 3483 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
    Finest
    Apr 24, 2017
    1
    可以
    superPershing
    superPershing
    OP
    Apr 24, 2017
    2
    @hand515 那是不是说在某种程度上没有学 shell 的必要了?
    jtsai
    jtsai
    Apr 24, 2017❤️1
    3
    @superPershing 学 shell 是学 shell 的思想,怎么跟 liunx 打交道。不学 shell 你也不知道怎么用 Python 跟 linux 打交道
    holyghost
    holyghost
    Apr 24, 2017❤️1
    4
    @superPershing 当然

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

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

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

    例如
    cat text.txt
    或
    ls ../*.txt

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

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

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