Date: Sun, 6 Jul 2014 11:54:56 +0200 From: Polytropon <freebsd@edvax.de> To: Jos Chrispijn <kernel@webrz.net> Cc: "freebsd-questions@FreeBSD.org" <freebsd-questions@FreeBSD.org> Subject: Re: Login and auto executes Message-ID: <20140706115456.537c5fba.freebsd@edvax.de> In-Reply-To: <53B9163E.3040406@webrz.net> References: <53B9163E.3040406@webrz.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 06 Jul 2014 11:26:22 +0200, Jos Chrispijn wrote: > (1) I have this regular user U1. After I log in to that user account, I > would like to start a script that does some other commandlines. > For this purpose I created .bash_profile and .bashrc in the U1 user > folder, containing a simple test command like 'ls': Directory. :-) > .bashrc > ls -alt > > In the .profile of the U1 user I put at the last line: > [ $BASH ] && [ -f ~/.bashrc ] && . ~/.bashrc This looks complicated. In my opinion, bash should do this automatically. According to "man bash", FILES section: /usr/local/bin/bash The bash executable /etc/profile The systemwide initialization file, executed for login shells ~/.bash_profile The personal initialization file, executed for login shells ~/.bashrc The individual per-interactive-shell startup file ~/.bash_logout The individual login shell cleanup file, executed when a login shell exits So it should be sufficient to place commands to be automatically executed at login time _only_ in ~/.bash_profile. > (2) I also tried putting the extra commands in the U1 .profile: > > --- cut --- > > echo '-- UPTIME --' > uptime > echo '' > echo '-- Who is ONLINE --' > who > > --- cut --- > > but this also is not executed. The file ~/.profile is reserved for /bin/sh. From "man sh": A login shell first reads commands from the files /etc/profile and then .profile in a user's home directory, if they exist. [...] Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. Note that using sh as an interactive shell doesn't look like a pleasant experience. :-) > What do I overlook and/or is there an > easier way of execting some after-login commands? Just use the correct file. Maybe call the commands explicitely (with full path) or define $PATH if needed. And finally make sure bash is invoked as the login shell, not "accidentally" csh. :-) In case of the C shell, use ~/.login to place commands to be executed after login, for your user, and ~/.cshrc for settings that should be applied to all interactive C shells. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140706115456.537c5fba.freebsd>