Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How to execute bash from within a python file?

I am wondering if it is possible to execute bash code from within a python file. I don't mean run a completely different bash file. I am looking for a method to easily execute bash code that is one line or longer in length. Specifically, I want to execute this code I got help with from a question I asked earlier today.

shopt -s nullglob
dirs=(*/)
cd -- "${dirs[RANDOM%${#dirs[@]}]}"

Answer*

Draft saved
Draft discarded
Cancel
1
  • 1
    "Platforms: Unix" and "Deprecated since version 2.6". Commented Jan 5, 2013 at 17:53

default

AltStyle によって変換されたページ (->オリジナル) /