You are not logged in.

#1 2018-05-02 06:03:14

MerryMurray
Member
Registered: 2018-05-02
Posts: 3

bash startup script for 'bash --login' option

Hi

In a terminal if I enter 'bash --login -c 'mybashfunction'
there should be a search order  specified by --login for a startup script to be executed
before mybashfunction is invoked.

In Debian I place . /source/myscripts  in ~/.profile. In arch
it does not work.

thanks

Murray

Offline

#2 2018-05-02 06:40:17

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,953

Re: bash startup script for 'bash --login' option

Bash manpage excpt.:

When  bash  is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists.  After reading that file, it  looks  for ~/.bash_profile,  ~/.bash_login,  and  ~/.profile,  in that order, and reads and executes commands from the first one that exists and is readable.  The --noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive login shell exits, or a non-interactive login shell executes the exit builtin command, bash reads and executes commands from the file ~/.bash_logout, if it exists.

When  an  interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.  This may be inhibited by using the --norc option.  The --rcfile file option  will  force  bash  to read and execute commands from file instead of ~/.bashrc.

strace the command if you're still unsure which considered file hits.
Also "it does not work" is a worthless error descritption (see the newbie corner stickies): it doesn't indicate which step fails. Reading ~/.profile, interpreting it, reading /source/myscripts - really that absolute path? - or interpreting that? Each step can fail and make it "does not work".

Edit: yeah - code tags no good for manpage ... quotes

Last edited by seth (2018-05-02 06:41:09)

Offline

#3 2018-05-02 07:42:55

MerryMurray
Member
Registered: 2018-05-02
Posts: 3

Re: bash startup script for 'bash --login' option

Thanks for the reply.

1) "it does not work" is a worthless - Yes you are right. should have said:
"bash --login -c 'list_folders /zdir'" produces
bash: list_folders: command not found
the script file did not get source from ~/.profile to the bash function was not found.

2) your cut and paste excerpt:
I am familiar with this and have followed it.  My script file is
sourced from ~/.profile.  It works in Debian for me and not in arch. Hence my
post.   You did not comment on whether this is right or wrong in arch.
It would be of more help if you had tried it out to see if it actually works the way
your pasted code says it should. 

3) strace produced 6 pages of code that is meaningless to me.

4) absolute path issue.  I don't understand. what should I code instead of
something like:
.  /mylibrary/myscripts.sh

Murray

Offline

#4 2018-05-02 11:40:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,523
Website

Re: bash startup script for 'bash --login' option

man BASH wrote:

it  looks  for ~/.bash_profile,  ~/.bash_login,  and  ~/.profile,  in that order, and reads and executes commands from the first one that exists

MerryMurray wrote:

I am familiar with this and have followed it.  My script file is sourced from ~/.profile.

No, clearly it isn't and therefore I suspect you haven't.  Do ~/.bash_profile or a ~/.bash_login exist?  If so, your source command is in the wrong file.  I suspect on debian you may not have these on your system.  If you created a new user following the wiki-guided defaults, you will havea ~/.bash_profile which would explain your symptoms.

Last edited by Trilby (2018-05-02 11:40:25)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2018-05-02 13:58:08

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,953

Re: bash startup script for 'bash --login' option

strace bash --login -c 'list_folders /zdir' 2>&1 | grep -E '(open|stat)' | grep $HOME

The question reg. the absolute path was meant to point out that "/source/myscripts" is a somewhat odd file (you'd expect anything "mystuff" somewhere in $HOME, thus the question whether the path is actually correct and should not be ~/source/myscripts or similar)

Offline

#6 2018-05-02 18:44:22

MerryMurray
Member
Registered: 2018-05-02
Posts: 3

Re: bash startup script for 'bash --login' option

Thanks again
Issue resolved.

1)it  looks  for ~/.bash_profile,  ~/.bash_login,  and  ~/.profile,  in that order, and reads and executes commands from the first one that exists
Yes. I already knew that but I missed ~/.bash_profile existed.  Removed it and problem solved.

2) Yes,  This is a throwaway environment while I am learning arch. 
just put it there  to keep it simple while testing.

Not sure how to mark this as solved.

Thanks gain

Murray

Offline

#7 2018-05-02 18:51:35

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: bash startup script for 'bash --login' option

You can mark your thread as [Solved] by editing your first post and prepending it to the title.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB