Pythonで/bin/shの代わりにbashシェルを使用する方法

Pythonで/bin/shの代わりにbashシェルを使用する方法

端末で実行できるコマンドがありますが、Pythonスクリプトから直接実行したいと思います。しかし、私のスクリプトはbashからコマンドを起動し、/bin/sh端末はbashです。

はい

私のスクリプトでは:

!macommande

/bin/sh: macommande: command not found

ターミナルにいる間:

[user@user] $ macommande

bash: macommande: command not found

ps:私のコマンドは以下ではうまく実行されますが、うまくbash動作しません/bin/sh

!ll

/bin/sh: ll: command not found

ターミナルにいる間:

[user@user] $ ll

rw-rw-r--  1 1614 Apr 10 16003 example
drwxrwxr-x  3 4096 Apr 10 10:13 config
drwxrwxr-x  3 4096 Apr 10 10:09 demo00

ベストアンサー1

シェルコマンドの前に感嘆符が付いているので、これはIpythonを使用していることを示します。これが本当なら、次の記事を読んでください。IpythonおよびShellコマンド

つまり、「!」を使用しないと、「list long」または「ll」コマンドが機能します。感嘆符。私はあなたの「macommande」も効果があると思います。

複数行のbashコマンドを入力するには、「%%bash」を使用できます。お役に立てば幸いです。

おすすめ記事