Skip to main content
63 votes
Accepted

Find out what scripts are being run by bash at login

If your system has strace then you can list the files opened by the shell, for example using echo exit | strace bash -li |& grep '^open' (-li means login shell interactive; use only -i for an ...
AlexP's user avatar
  • 10.5k
25 votes
Accepted

How to make custom zsh script executable automatically?

You're mixing up scripts and functions. Making a script A script is a standalone program. It may happen to be written in zsh, but you can invoke it from anywhere, not just from a zsh command line. ...
Gilles 'SO- stop being evil''s user avatar
21 votes
Accepted

Welcome banner stopping scp

Commands running on top of the ssh transport do not expect large amounts of output before they can start their server. This will affect a number of utilities. The solution is to have your ...
Chris Davies's user avatar
21 votes
Accepted

SSHing into system with ZSH as default shell doesn't run /etc/profile

ZSH just works in this way. /etc/profile is NOT an init file for ZSH. ZSH uses /etc/zprofile and ~/.zprofile. Init files for ZSH: /etc/zshenv ~/.zshenv login mode: /etc/zprofile ~/.zprofile ...
Simba's user avatar
  • 1,772
20 votes
Accepted

Where do /root/.bashrc and /root/.profile come from on a Debian system?

root's files are copied from base-files: if they're missing, its postinst copies /usr/share/base-files/dot.bashrc to /root/.bashrc and /usr/share/base-files/dot.profile to /root/.profile. Additionally,...
Stephen Kitt's user avatar
20 votes

How can I change what's displayed at a login shell?

The OP clearly is asking about messages displayed AFTER log in, all "/etc/issue" are displayed BEFORE login+password is entered so are off-topic. The 'login shell' steps are: show messages contained ...
Valerio's user avatar
  • 315
19 votes
Accepted

bash does not know the letter 'p'

Besides the files you mentioned, there could be .inputrc in effect that changes the interpretation of the p key. Edit: maddingl (the OP) confirms: That's it. I had left the following in there: # fix ...
choroba's user avatar
  • 47.6k
18 votes

Ash profile/configuration file

A non-login 'ash' or 'dash'-based shell may also 'source' a file if that file's full path is contained in the environment variable ENV (or perhaps SHINIT). So if you set that somehow (Maybe in your ~/....
spechter's user avatar
  • 281
17 votes
Accepted

Set environment variables for gnome on wayland and bash on virtual terminals (or ssh)

Systemd version 233 (March 2017) added support for setting environment variables in ~/.config/environment.d/*.conf. See the environment.d man page and the discussion that led to the feature on this ...
Jack O'Connor's user avatar
17 votes
Accepted

Why does man complain about a function defined in .profile?

man is not reading your ~/.profile but it will run sh to interpret some command lines (or to interpret nroff which at least on my system is a sh script wrapper to groff), and on your system sh happens ...
Stéphane Chazelas's user avatar
15 votes
Accepted

Could setting the permission on these files to 600 render my OS unusable? .bash_logout, .bashrc, .profile

TL,DR: .bash* can be 600, but chmod -R 600 is dangerous. You can make your home directory accessible to only you: chmod 700 ~ This doesn't need to be recursive. It's impossible to access a file ...
Gilles 'SO- stop being evil''s user avatar
12 votes

Find out what scripts are being run by bash at login

Reviving this question because strace is an overkill here. Execute bash and carve it out of the output. -li is login interactively, -x prints out what bash is doing internally, and -c exit tells bash ...
Naomi's user avatar
  • 229
12 votes

Why does man complain about a function defined in .profile?

Don't export functions, especially functions that require a non-default bash configuration. Exported functions are a bash feature, so they don't affect other shells. But they affect all invocations of ...
Gilles 'SO- stop being evil''s user avatar
11 votes
Accepted

Why have both .bash_profile and .bashrc?

Only .bashrc is run on non-login shells, while only .bash_profile is run on login shells. .bashrc should typically contain things you want to set in every shell you open, like aliases, functions, etc. ...
Munir's user avatar
  • 3,362
11 votes
Accepted

$HOME/bin dir is not on the $PATH

From the top of ~/.profile: # ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/...
Tigger's user avatar
  • 3,687
10 votes
Accepted

How can I restore the Bash prompt?

PS1='[\u@\h \W]\$ ' Search the manual for PS1.
icarus's user avatar
  • 18.2k
10 votes
Accepted

How to write an automatically sourced shell script to /etc/profile

/etc/profile is a file. Hence the error when trying to create /etc/profile/foo.sh. /etc/profile.d is the directory you're thinking of. Scripts placed in there get sourced on login. In your example,...
steve's user avatar
  • 22k
7 votes

Where are gnome-terminal profiles stored on a Linux distribution?

On my Ubuntu 16.04, open dconf editor (as the user) org > gnome > terminal > legacy > profiles > ...
GMaster's user avatar
  • 6,412
7 votes

Welcome banner stopping scp

You cannot print anything in non-interactive session. That breaks any clients that use a strict protocol, such as SFTP or SCP. Use /etc/motd (which is used for interactive sessions only). Or use ...
Martin Prikryl's user avatar
7 votes
Accepted

What to do when .profile does not exist for editing PATH?

If you have a ~/.bash_profile file, then edit that instead (since you seems to be using bash (since you are on Linux and since you mention that there is a ~/.bashrc file present that you've edited ...
Kusalananda's user avatar
  • 338k
7 votes
Accepted

How can I make my script in /etc/profile.d to run after all other scripts in same directory?

Just number the scripts, like 01-firstscript.sh, 99-lastscript.sh, if it is showing in last in ls -l, you're done. If the files are not supposed to be numbered (installed by distribution), just ...
Luciano Andress Martini's user avatar
7 votes

SSHing into system with ZSH as default shell doesn't run /etc/profile

sshd runs a login shell when the client doesn't send any command to run. That's to mimic the behaviour of rsh which was calling the rlogind service instead of the rshd one when not given any command ...
Stéphane Chazelas's user avatar
6 votes

What do the scripts in /etc/profile.d do?

jordanm's answer is incorrect. /etc/profile is not sourced by all shells. As you point out, it is not sourced by csh, tcsh - I'm not sure about zsh. It is sourced by Bourne shell (sh) derivatives, ...
Damocles's user avatar
6 votes

$HOME/bin dir is not on the $PATH

The rules for in-sourcing shell startup files are complex. It's likely that with your setup, .profile is not getting included when you open up a new terminal within an X session (try putting an echo ....
Petr Skocik's user avatar
5 votes

Set environment variables for gnome on wayland and bash on virtual terminals (or ssh)

This is the workaround that I use for the exact same problem: Step 1 Create a script that sources ~/.profile and make that script executable. Let's call it /path/to/startup.sh. It could look ...
Tudor Vișan's user avatar
5 votes
Accepted

Functions in ~/.bash_profile not found in an interactive shell

Functions defined in .bash_profile are only available in the shell that reads .bash_profile and not available in sub shells. When you open a terminal window you may be opening a non login shell. ...
Stephen Harris's user avatar
5 votes
Accepted

How to automatically load tmux at login, but not if already inside tmux?

tmux sets the $TMUX variable to point to the socket, so you can do something like if [ -z "$TMUX" ] then .... fi The stuff inside the test will only be run if the variable is not set - ie you're ...
Stephen Harris's user avatar
5 votes
Accepted

How to find out which files have defined "alias"es?

Along the lines of Stéphane's similar answer, here's a way to run an interactive bash shell in trace mode (running the single command exit), piped to a grep that shows only the source and alias ...
Jeff Schaller's user avatar
  • 67.6k
5 votes
Accepted

How do you run a command with sudo in `~/.profile`?

If you put the command in your ~/.profile, it will run every time you launch a login shell. Some terminal emulators allow you to use a login shell for each terminal window. Do you want your command ...
glenn jackman's user avatar
5 votes
Accepted

Is there a totally empty Bash file I can use (or create) to extend .bashrc and .profile?

I know that by principle, one shouldn't change .bashrc and common changes like creating an alias should better be done in .profile instead. This doesn't make any sense. You probably misunderstood ...
Gilles 'SO- stop being evil''s user avatar

Only top scored, non community-wiki answers of a minimum length are eligible