Subject: Re: bug#38057: (shell-command "alias" "bash-aliases" "bash-errors") - Shell command succeeded with no output

From: Stefan Kangas <[email-masked]>
Date: Thu, 07 Nov 2019 04:37:59 +0100

tags 38057 + notabug
close 38057
thanks

Eli Zaretskii <[email-masked]> writes:

>> From: arthur miller <[email-masked]>
>> Date: Mon, 4 Nov 2019 11:52:38 +0000
>> 
>> When I run 'alias' (a bash command) from within elisp I don't get list of aliases. It used to work fine, but in my
>> latest build from git as of 2019-11-04 (4th november) it does not. Maybe it stopped to work earlier, I don't
>> know, I was reworking my init file, so I didn't had it in for like a month or so, anyway, when I test it today I don't
>> get the 'alias' command to work at all. It works from ansi-term, but not interactively or from an elisp script.
>> 
>> I get message that shell command succeeds without any output. The line (shell-command "alias"
>> "bash-aliases" "bash-errors") is part of a little script I posted on Emacs Wiki earlier this year
>> https://www.emacswiki.org/emacs/EshellAlias.
>> 
>> Is it a bug or do I something wrong? I am sorry, I am not an expert on Emacs, so I am a bit unsure.
>
> Does the following discussion help to understand the issue?
>
>   https://stackoverflow.com/questions/1615877/why-aliases-in-a-non-interactive-bash-shell-do-not-work

The above link makes the situation clear: your .bashrc is not
processed by non-interactive shells.  I don't see how this could have
worked earlier or how it could work now.

One work-around, if you really need this, would be to put the relevant
aliases in a new file, say "~/.bash_aliases", and then running:

    (setenv "BASH_ENV" "~/.bash_aliases")
    (shell-command "alias")

This utilizes the fact that the file pointed to by the BASH_ENV
environment variable will always be sourced.  But be aware that this
may cause problems, depending on the contents of your
"~/.bash_aliases" file.  For more information on this, see the bash
man page section "INVOCATION".

In other words, this is all working as expected, and I'm closing this
as notabug.

Best regards,
Stefan Kangas