Hot answers tagged

80 votes

Standard place for user defined bash_completion.d scripts?

For non-XDG environments and bash-completion <= 2.8 Here is how a local user can have a working ~/.bash_completion.d/ directory. edit file: nano ~/.bash_completion, add the following: for bcfile ...
Russell E Glaue's user avatar
26 votes

Standard place for user defined bash_completion.d scripts?

The FAQ has been updated. There is now a standard place for local completions. Q. Where should I install my own local completions? A. Put them in the completions subdir of $...
hallidave's user avatar
  • 381
20 votes
Accepted

bashrc not loaded in /bin/bash shell

the ~/.bashrc file is loaded for interactive non-login shells, that's why running /bin/bash from ssh works as you expect. For login shells (amongst others) ~/.bash_profile is read. Typically your ~/....
user9517's user avatar
  • 116k
18 votes
Accepted

~/.bashrc is NOT sourced on ssh 'command'

Adding my bit to the old thread for information because the accepted answer is not the real reason for .bashrc not being read for an ssh command. I got the hint after reading this answer. The second ...
Saumya Kanta Swain's user avatar
15 votes

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

Other people have asked the same thing on the CentOS bug tracker. The earliest post I found was this one. /usr/local/bin is hardcoded in /bin/bash. https://bugs.centos.org/view.php?id=10200 https://...
user5870571's user avatar
  • 3,104
11 votes

Straight forward way to run ssh-agent and ssh-add on login via SSH?

Another alternative is to add this to your .bashrc. This has the same advantage as Erik's answer (ensuring a single instance) but doesn't require an additional package. # SSH Agent should be running, ...
womblerone's user avatar
9 votes

Standard place for user defined bash_completion.d scripts?

At least bash-completion 2.8 and later enable option to place local Bash completions in directory ${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions The ...
jarno's user avatar
  • 193
9 votes

Straight forward way to run ssh-agent and ssh-add on login via SSH?

One alternative is to use Funtoo's Keychain. Then you can stick this one-liner in your bash shell: eval $(keychain --eval id_rsa) That does the same thing (launches ssh agent, etc.), while also not ...
Erik Aronesty's user avatar
8 votes
Accepted

Can't use functions exported from .bashrc in a bash script

Check http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files Invoked non-interactively When Bash is started non-interactively, to run a shell script, for example, it looks for ...
glenn jackman's user avatar
8 votes
Accepted

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

In the bash source "config-top.h" has this: /* The default value of the PATH variable. */ #ifndef DEFAULT_PATH_VALUE #define DEFAULT_PATH_VALUE \ "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/...
Schrute's user avatar
  • 807
8 votes

~/.bashrc is NOT sourced on ssh 'command'

From the INVOCATION chapter of man bash: When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. ...
telcoM's user avatar
  • 4,518
7 votes

Best Practice to obscure path to keypair in bash_profile?

Hiding your key in an unusual place is not making it any safer. If you undertake basic good practice for key management there's really no need to do anything extra. Your private key needs to be kept ...
user9517's user avatar
  • 116k
6 votes

Standard place for user defined bash_completion.d scripts?

A simpler solution is to use the nullglob option. While this isn't portable, neither are bash completions. So portability doesn't matter. Also, you'll want to use quotes around the variable when ...
npmccallum's user avatar
6 votes

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

It definitely looks hard coded into /bin/bash strings /bin/bash | grep "\/usr\/local\/bin" /usr/local/bin:/bin:/usr/bin which seems to be the default PATH.
user9517's user avatar
  • 116k
5 votes
Accepted

'source .bash_profile' fails but 'source path/to/.bash_profile' works

You are using bash in POSIX mode. From man bash under source filename [arguments] If filename does not contain a slash, file names in PATH are used to find the directory containing filename... ...
DerfK's user avatar
  • 19.6k
5 votes

Where does the bash PATH on CentOS 7 get /usr/local/bin from?

In addition to previous answers; If you are reaching you VM by ssh this could has sense. In /etc/ssh/sshd_config: # This sshd was compiled with PATH=/usr/local/bin:/usr/bin
pbacterio's user avatar
  • 276
5 votes
Accepted

Aliasing Server Name in SSH Command

This should work: create a file $HOME/.ssh/config (or in /etc/ssh/ssh_config, if you want to install that alias system-wide), and put the following config inside: Host myalias Hostname very-long-...
Martin's user avatar
  • 2,324
4 votes

Convenient date/time stamping console interaction e.g. using shell aliases?

You can simply modify your shell prompt PS1 variable to show current timestamp. One of the following can be used: \t the current time in 24-hour HH:MM:SS format \T the current time in 12-hour ...
Khaled's user avatar
  • 36.7k
4 votes
Accepted

sourcing environment variable in bashrc: directly vs export from file yields different result - why

You forgot the export in your .env file, so the variable isn't actually an environment variable. Shell variables are not exported to environment by default. Only assignments to an already exported ...
u1686_grawity's user avatar
3 votes

Standard place for user defined bash_completion.d scripts?

The answer by Russell E Glaue is great but its ~/.bash_completion is incomplete. The problem is when ~/.bash_completion.d/ is empty and subsequently for f in ~/.bash_completion.d/* prints the ...
Mateusz Piotrowski's user avatar
3 votes

Best Practice to obscure path to keypair in bash_profile?

If someone has enough access to your box to harvest your keys, it's game over anyway. Don't worry about it.
EEAA's user avatar
  • 110k
3 votes

Running a bash script from systemd as if I logged in

The difference between running the script via systemd and running it directly is the environment. You can test it like this. In your Unit file, add this to the [Service] section, for testing: ...
Mark Stosberg's user avatar
3 votes

Login without running bash_profile or bashrc

ssh -t user@host "bash --norc --noprofile -c '/bin/rm .bashrc'"
wytten's user avatar
  • 131
3 votes

How to define envrionment variables accesisble by crontab's run and bash shell

I don't think you can do this in the crontab directly. The crontab file isn't a shell script so trying to source a script containing envvars into it doesn't work . /path/to/envvars crontab won't ...
user9517's user avatar
  • 116k
3 votes
Accepted

Logout user if they break a bashrc command

You can add line trap '' 2 at start of you script to disable CTRL+C and trap 2 in end to enable CTRL+C functional. This will prevent user from brake you script execution. Note that this should ...
Slipeer's user avatar
  • 3,305
3 votes

How to rename system commands e.g., shutdown in Ubuntu Linux

shutdown, rm and reboot commands rm is required for a POSIX environment. If you don't want a user to delete a file, remove their write permission on the directory containing it, and don't give them ...
John Mahowald's user avatar
3 votes
Accepted

How to set a command alias that will be respected in a shebang

Is it possible to set an alias for the php command which is respected in the shebang? No because shebang is parsed by kernel which doesn't know or care about your shell-specific aliases and ...
Arkadiusz Drabczyk's user avatar
3 votes
Accepted

How to Make the IP Address Appear as Part of Bash Prompt?

Letting your prompt actually derive that IP-address is, as far as I know, rather more difficult. Bash does not provide a ready-made variable to use for that according to the list with special ...
diya's user avatar
  • 1,799
2 votes
Accepted

printing user of subshell obtaining root via su -

Previously I recommend the script below... I found a better way! :) Just exec: logname Also, you can use $SUDO_USER, but doesn't work if you are using sudo su - By the way, who am i is like who -m ...
Jose Raul Barreras's user avatar
2 votes

ansible-playbook not able to use .bashrc env variables

I use this one: - shell: . ~/.bashrc && echo $LS_COLORS args: executable: /bin/bash register: result - set_fact: ls_colors: "{{ result.stdout }}"
Wernfried Domscheit's user avatar

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