I have a Fedora 28 installation on which I have installed the bash bash-completion package.
I have run the following:
source /etc/profile.d/bash_completion.sh
And bash completion works as expected.
However, whenever I re-login, I must run the above command before bash completion starts working - it is not enabled automatically.
I have checked the permissions of the bash_completion.sh file and even added the x flag, but it is still not enabled automatically.
How can I get this working?
The /etc/bashrc file provided by the setup package, will source all scripts in /etc/profile.d/ by default. Also, by default your ~/.bashrc, should have the following (you can verify it's the default by looking in /etc/skel/.bashrc) :
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Here's the relevant part (towards the end) of that file that I see on my system (Fedora 28 Workstation):
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
Here's the version of setup that I'm using (and proof that that's where it comes from):
$ rpm -q --whatprovides /etc/bashrc
setup-2.11.4-1.fc28.noarch
Related
I am currently in the ~/ directory in terminal on my Mac, and trying to configure the .bash_profile.
I am trying to issue the cat command to view its contents. The result is the following:
# The next line updates PATH for the Google Cloud SDK. if [ -f '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud. if [ -f '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc'; fi export PATH="/usr/local/opt/ncurses/bin:$PATH"
I receive the following when I try to view the .bashrc file:
if [ -f '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc'; fi
Any ideas why am I not seeing the user environment variables as I should be ?
I read this page from the bash reference manual, which tells me that bash reads /etc/profile then my home directory. I wasn't able to find an environment variable to tell bash to read some subdirectory, ie ~/.bash.d. I suspect that I need to put some line in /etc/profile along the lines of:
BASHENVIRONMENTVARIABLE="~/.bash.d"
ie. for zsh that variable is ZDOTDIR.
/etc/profile has the following description:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
How about writing a script to read files under ~/.bash.d as same as this?
if [ -d ~/.bash.d ]; then
for i in ~/.bash.d/*; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
Or maybe you can do it with eval command.
eval $(cat ~/.bash.d/*)
The startup scripts (~/.bashrc, ~/.bash_profile, ~/.bash_login, etc) are all expected to be located in the home folder.
To source the startup from a different folder, simply add a source (or .) command to the "official", and place all the setting in the desired location (~/.bash.d)
# This is ~/.bashrc
source ~/.bash.d/.bashrc
# This is ~/.bash_login
source ~/.bash.d/.bash_login
Note that the 'BASH_ENV' will usually include absolute path, to allow it to work regardless of the directory where bash in invoked.
I tried to install cisco packet tracer on my mac. It was a sh script to install it. I ran it but not in su and it did some mess on my mac. After 1min i saw that my disk was full, since the script copied repertories everywhere.
Now, when i launch my terminal, the commands i recently installed (npm, brew, cordova...) are not recognized anymore, and there is not my user name at the beginning of the line, there is
-bash-3.2$
At every launch of the terminal, i get this error on the top of it :
Last login: Wed Jan 4 17:04:13 on ttys000
-bash: /etc/profile: line 1: syntax error near unexpected token `('
-bash: /etc/profile: line 1: `-e \n# System-wide .profile for sh(1)\n\nif [ -x /usr/libexec/path_helper ]; then\neval `/usr/libexec/path_helper -s`\nfi\n\nif [ "${BASH-no}" != "no" ]; then\n[ -r /etc/bashrc ] && . /etc/bashrc\nfi\nPT7HOME=/Users/myusername/Documents/pt'
I deleted the folder /Users/myusername/Documents/pt, but it seems that this is where the error is coming from. Thank you in advance for your help.
The error message implies that your /etc/profile, which by default looks like
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
was intended to be modified by adding a single line to the bottom
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
PT7HOME=/Users/myusername/Documents/pt
However, something went wrong, and in addition to adding a few extra characters to the beginning of the file, the indentation was removed and the newlines were converted to literal \n sequences, resulting in the contents becoming a single line, perhaps
-e \n# System-wide .profile for sh(1)\n\nif [ -x /usr/libexec/path_helper ]; then\neval `/usr/libexec/path_helper -s`\nfi\n\nif [ "${BASH-no}" != "no" ]; then\n[ -r /etc/bashrc ] && . /etc/bashrc\nfi\nPT7HOME=/Users/myusername/Documents/pt
Without further information, I would suggest that you could simply edit the file to look like the modified version above. However, #n.m.'s and #cdarke's suggestions should both be taken: restore from backup if possible, and contact user support to figure out what exactly may be wrong with the script.
I'm trying to run this bash shell script to create directories for vim syntax highlighting on Ubuntu 13.04 (via Vagrant 1.4.1 on Windows 7).
#!/usr/bin/env bash
basevim="$HOME/.vim"
ftdetect="${basevim}/ftdetect"
indent="${basevim}/indent"
syntax="${basevim}/syntax"
echo "Setting up VIM for syntax highlighting"
#Create directories for vim syntax highlighting
if [ ! -d "$basevim" ]; then
echo "Adding VIM syntax highlighting dirs"
mkdir "$basevim"
mkdir "$ftdetect"
mkdir "$indent"
mkdir "$syntax"
else
if [ ! -d "$ftdetect" ]; then
mkdir "$ftdetect"
fi
if [ ! -d "$indent" ]; then
mkdir "$indent"
fi
if [ ! -d "$syntax" ]; then
mkdir "$syntax"
fi
fi
This is executing as a provision.sh script for Vagrant so as far as I know it should run as root. I can see the echo'd message so it's taking the first branch. But for the life of me I can't seem to get this to work; no complaints but the directories don't get created. If I set those variables on an interactive prompt, I need to do sudo mkdir ftdetect (etc.) to get the directories created. Strangely I don't need to sudo to get the .vim directory created--at least that's what I recall.
I tried
if [ ! -d "${basevim}" ]; then
but that didn't do anything. I also tried
basevim="{$HOME}/.vim"
--also no dice. Any thoughts of what I may be missing? As I say, as far as I know it shouldn't be necessary to sudo on a provisioning script on Vagrant. I can tell the script is getting run because those echo'd messages are getting output.
Your script could be replaced by
mkdir -p "$HOME/.vim"/{ftdetect,indent,syntax}
As for the directories not appearing... Where are you looking for them?
Running this as root would create them in root's home directory, /root/, and not in the user's home directory /home/username. When in doubt, use absolute path names (and chown as needed afterwards).
Every time I log into my VPS I must run source ~/.bashrc before I can run any rvm, ruby, or gem commands.
Why is this? Can't make it load by default?
ssh deployer#xxx
ruby -v
-bash: ruby: command not found
source ~/.bashrc
ruby -v
ruby 1.9.3p429 (2013-05-15 revision 40747) [i686-linux]
I installed rvm under deployer.
I have ~/.bash_pofile which is empty. I also have ~/.profile which has the following in it:
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
My ~/.bashrc has this at the top:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
From the bash man page:
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.
So in your case, the (empty) ~/.bash_profile is being executed, and your ~/.profile (and thus your ~/.bashrc) are ignored. To solve this, you'll either need to delete your ~/.bash_profile, or else move the contents of ~/.profile into ~/.bash_profile.
When you log in, if Bash can find a file named .bash_profile in your home directory it will execute it and do not even search for a .profile file. Thus you have two choices, either remove the empty .bash_profile file or copy the contents of .profile to .bash_profile.
Moving the information from .bashrc to the other files, as suggested by others is one way to do it.
Otherwise, this snippet of code will do the same thing, without needing to move the contents, or remove the file. Depending on the ways you have things set up, you may not want to delete a file, if it has relevant information in it for other tasks, other than interactive login.
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Though using the files as they are intended to be used by reading the documentation can definitely alleviate some frustration.