comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Spawning Unix commands from IDL under bash
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Spawning Unix commands from IDL under bash [message #93307] Fri, 10 June 2016 11:20 Go to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
I've recently succumbed to peer pressure to switch my (Mac and Linux) shell from tcsh to bash.

Everything is working fine except that I do not have access to the aliases defined in my .bash_profile (Mac) or .bashrc (linux) files when spawning from IDL. For example in my .bash_profile file I have

alias ll="ls -l"

I am able to use this alias at the system prompt but it is not recognized when spawning from the IDL prompt

IDL> $ll (or IDL> spawn,'ll' )
bash: ll: command not found

Note that this is not a PATH problem and IDL> spawn,'ls' does work.


A google search revealed a user asking a similar question 10 years ago
https://docs.astro.columbia.edu/ticket/160

and the "solution" was to use tcsh instead of the bash shell. But there must be some way for bash users to get the same behavior issuing a command from SPAWN within IDL, that they do when issuing the command from the system prompt.

Thanks, --Wayne
Re: Spawning Unix commands from IDL under bash [message #93309 is a reply to message #93307] Fri, 10 June 2016 11:30 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Friday, June 10, 2016 at 2:20:05 PM UTC-4, wlandsman wrote:
> I've recently succumbed to peer pressure to switch my (Mac and Linux) shell from tcsh to bash.
>
> Everything is working fine except that I do not have access to the aliases defined in my .bash_profile (Mac) or .bashrc (linux) files when spawning from IDL. For example in my .bash_profile file I have
>
> alias ll="ls -l"
>
> I am able to use this alias at the system prompt but it is not recognized when spawning from the IDL prompt
>
> IDL> $ll (or IDL> spawn,'ll' )
> bash: ll: command not found
>
> Note that this is not a PATH problem and IDL> spawn,'ls' does work.

I think you are spawning an interactive non-login shell. See here...

https://www.gnu.org/software/bash/manual/html_node/Bash-Star tup-Files.html

So it may depend whether your alias is defined in .bashrc or .bash_profile.

Craig
Re: Spawning Unix commands from IDL under bash [message #93311 is a reply to message #93309] Sat, 11 June 2016 18:59 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
Wow, bash turns out to be a lot more complicated than tcsh in this case.

Craig is correct (thanks!) that one creates a non-interactive shell when SPAWNing a bash command from IDL. But a non-interactive bash shell doesn't read .bashrc or .bash_profile or *any* file by default. Instead you have to set the environment variable BASH_ENV to point to the file with the alias commands.

But we are still not done because we need to tell bash to expand aliases. I have a vague idea why this is so, but I think my explanation would just come out as hand-waving. Anyway, one has to include the command

shopt -s expand_aliases

in the file containing the aliases.

Some of these tips come from the following post:

http://stackoverflow.com/questions/1615877/why-aliases-in-a- non-interactive-bash-shell-do-not-work

--Wayne


On Friday, June 10, 2016 at 2:30:12 PM UTC-4, Craig Markwardt wrote:
> On Friday, June 10, 2016 at 2:20:05 PM UTC-4, wlandsman wrote:
>> I've recently succumbed to peer pressure to switch my (Mac and Linux) shell from tcsh to bash.
>>
>> Everything is working fine except that I do not have access to the aliases defined in my .bash_profile (Mac) or .bashrc (linux) files when spawning from IDL. For example in my .bash_profile file I have
>>
>> alias ll="ls -l"
>>
>> I am able to use this alias at the system prompt but it is not recognized when spawning from the IDL prompt
>>
>> IDL> $ll (or IDL> spawn,'ll' )
>> bash: ll: command not found
>>
>> Note that this is not a PATH problem and IDL> spawn,'ls' does work.
>
> I think you are spawning an interactive non-login shell. See here...
>
> https://www.gnu.org/software/bash/manual/html_node/Bash-Star tup-Files.html
>
> So it may depend whether your alias is defined in .bashrc or .bash_profile.
>
> Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: no text on new graphics - missing path or bad file?
Next Topic: Multi plots conditions

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:14:09 PDT 2025

Total time taken to generate the page: 0.00747 seconds