3 ms·
As a non Linux admin I struggle to understand why you would want the differential between a login and a non login script. One interesting thing I discovered wa
by nickthemagicman 6y ago
As a non Linux admin I struggle to understand why you would want the differential between a login and a non login script.
One interesting thing I discovered was there are system-wide profile and bash profile scripts.
/etc/profile
/etc/.bashrc
In case you need to set these for every account.
- toast0 6y agoOften people have login scripts that print things like how much mail you have, etc. That's not necessary or desirable in a non-login context.
- CaptArmchair 6y agoThis article does a fair bit of explaining: [1] > The primary thing to understand is that the rc files are for all shell invocations while the profiles are strictly for interactive shells. An interactive shell is where you (end user) types the command while an non-interactive shell is when shells are launched by other programs such as a script with #!/bin/bash as SHEBANG value [1] https://www.golinuxcloud.com/bashrc-vs-bash-profile/ https://www.golinuxcloud.com/bashrc-vs-bash-profile/ So, what are use cases in which a non-interactive shell is launched? One example is a cron jobt that runs every night. It's basically the "cron" process executing a command which could be a bash script. Another example would be startup scripts that launch background processes and services which you'd find in /etc/system. There's a distinction between interactive v. non-interactive and login v non-login as well [2] https://dev.to/bijaykumarpun/linux-shells-interactive-non-interactive-login-and-non-login-2ddp https://dev.to/bijaykumarpun/linux-shells-interactive-non-in... Typical issue would be adding something to your PATH variable in .profile, having your script work just fine in a shell, but having it fail when you run it as a cron job because .profile never gets sourced by cron.
- deleted 6y ago[deleted]
- devnull255 6y agoIn Linux, processes scheduled in cron, systemd or other schedulers don't require and may sometimes have issues with the customizations in login scripts for interactive sessions. Login scripts may expect input from the user keyboard, or may depend on environment variables that exist when a login script is executed, but not when nonlogin scripts execute.
- jwilk 6y agoSchedulers run non-interactive non-login shells, which don't load any of these files.
- ansible 6y agoThese days, I fail to see any need to put anything in the .bashrc file. If there is some non-interactive use of bash, I just want a clean environment, and everything scp or ssh needs should be on the standard $PATH. There's no point in putting anything in .profile either, because if I am running an interactive session, I will be using bash. I don't care about the config for dash or whatever. And any scripts should completely specify their required functions, $PATH and whatever inside the script itself. Use 'source' to pull in common functions.