Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Any shell has several sets of features.</p> <ul> <li><p>The Essential Linux/Unix commands. All of these are available through the <a href="https://docs.python.org/3/library/subprocess.html" rel="noreferrer">subprocess</a> library. This isn't always the best first choice for doing <em>all</em> external commands. Look also at <a href="https://docs.python.org/3/library/shutil.html" rel="noreferrer">shutil</a> for some commands that are separate Linux commands, but you could probably implement directly in your Python scripts. Another huge batch of Linux commands are in the <a href="https://docs.python.org/3/library/os.html" rel="noreferrer">os</a> library; you can do these more simply in Python.</p> <p>And -- bonus! -- more quickly. Each separate Linux command in the shell (with a few exceptions) forks a subprocess. By using Python <code>shutil</code> and <code>os</code> modules, you don't fork a subprocess.</p></li> <li><p>The shell environment features. This includes stuff that sets a command's environment (current directory and environment variables and what-not). You can easily manage this from Python directly.</p></li> <li><p>The shell programming features. This is all the process status code checking, the various logic commands (if, while, for, etc.) the test command and all of it's relatives. The function definition stuff. This is all much, much easier in Python. This is one of the huge victories in getting rid of bash and doing it in Python.</p></li> <li><p>Interaction features. This includes command history and what-not. You don't need this for writing shell scripts. This is only for human interaction, and not for script-writing.</p></li> <li><p>The shell file management features. This includes redirection and pipelines. This is trickier. Much of this can be done with subprocess. But some things that are easy in the shell are unpleasant in Python. Specifically stuff like <code>(a | b; c ) | something &gt;result</code>. This runs two processes in parallel (with output of <code>a</code> as input to <code>b</code>), followed by a third process. The output from that sequence is run in parallel with <code>something</code> and the output is collected into a file named <code>result</code>. That's just complex to express in any other language.</p></li> </ul> <p>Specific programs (awk, sed, grep, etc.) can often be rewritten as Python modules. Don't go overboard. Replace what you need and evolve your "grep" module. Don't start out writing a Python module that replaces "grep".</p> <p>The best thing is that you can do this in steps.</p> <ol> <li>Replace AWK and PERL with Python. Leave everything else alone.</li> <li>Look at replacing GREP with Python. This can be a bit more complex, but your version of GREP can be tailored to your processing needs.</li> <li>Look at replacing FIND with Python loops that use <code>os.walk</code>. This is a big win because you don't spawn as many processes.</li> <li>Look at replacing common shell logic (loops, decisions, etc.) with Python scripts.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload