I have commands that could be executed in a terminal, but I want to execute them directly from my python script, except that my script it launches the commands in /bin/sh, and my terminal is bash.


in my script python:


/bin/sh: macommande: command not found

while on the terminal:

[user@user] $ macommande

bash: macommande: command not found

p.s.: my commands work well on bash, but not on /bin/sh:


/bin/sh: ll: command not found

while on the terminal:

[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
  • you can use bash to run the command by prepending /bin/bash like so: /bin/bash macommande
    – mkc
    Apr 17 '19 at 13:14
  • This question should explain which shell /bin/sh actually is on this system, because it appears that /bin/sh is the Bourne Again shell and the underlying premise of the question is false. That error message is in the form printed by the Bourne Again shell.
    – JdeBP
    Apr 17 '19 at 13:25
  • 1
    ll is an alias, defined in ~/.bashrc. Do other commands work e.g. ls. Jul 27 '19 at 10:32

Because you have preceded your shell command with the exclamation point, that indicates to me that you are using Ipython. If that is true, I would recommend that you read that article: Ipython and Shell commands.

The short answer is that ‘list long’ or ‘ll’ command will work if you don’t use ‘!’ the exclamation point. I suspect that your ‘macommande’ will work also.

To enter a multi-line bash command you can use ‘%%bash’. Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.