Tag Info

New answers tagged

0

The prompt variable $PS1 was probably not set, so the built-in default \s-\v\$ is used. When bash starts up interactively, it sources a configuration file, usually either ~/.bashrc or ~/.bash_profile, presuming they exist, and this is how a fancier prompt is set. From man bash: INVOCATION [...] When bash is invoked as an interactive login ...


3

You mix up two commands. [ is not eqivalent to if. [ is equivalent to test. if is not even a simple command but a reserved word (like [[), part of a control structure. if ... then ... else ... fi is nearly eqivalent to ... && { ...; true; } || { ... }


4

You can just chain &&'s, no need to nest conditionals here: [ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion works.


0

I follow the very common practice of putting my alias definition in ~/.bash_aliases and then calling that from .bashrc with [ -f ~/.bash_alias ] && source $HOME/.bash_alias


0

Solved by the following: Placed a guard around my PATH manipulation code in .profile if [ "$PATHS" != "true" ]; then export PATHS="true" #Manipulate and export PATH over here fi Removed file-level guards around .bash_profile and .bashrc IMPORTANT: RESTARTED the tmux server. (killall tmux) -- the manual indicates the server maintains its ...


1

It's as simple as shopt -s autocd 2>/dev/null If you want to see whether an option is available but not change its value, call shopt without -s or -u: if shopt autocd >/dev/null 2>/dev/null; then …


3

autocd was introduced into bash with version 4. So, a general cross-platform solution should be: [ "${BASH_VERSINFO[0]}" -ge 4 ] && shopt -s autocd ${BASH_VERSINFO[0]} is bash's major version. The minor version, should you ever need it, is ${BASH_VERSINFO[1]}. See man bash for more on BASH_VERSINFO.


0

A simple approach would be to check the OS name and act accordingly. I don't know what uname will return on OSX but presumably it will be different. You can therefore do something like this: [[ $(uname) = Linux ]] && shopt -s autocd That said, are you sure you need to do this? OSX runs login shells by default and the ~/.bashrc is ignored unless ...


0

I use the parse_git_branch function myself and I've found the following works well and gives me lots of info (and a carriage return!): parse_git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' } PS1='\033[01;31m\]\t\033[00m\]:' PS1=$PS1'\[\033[01;32m\]\u@\h\[\033[00m\]:' ...


0

This is a perfect use-case for ${parameter+substitution} since we're talking about parameters after all. _src_release() { . ${RELEASE:=/path/to/fallback} } <<GET_RELEASE ${PREFERRED="$(whatever gets you /path/to/preferred)"} ${NEXT_BEST="$(something else gets you /path/to/next/best)"} ${IF_YOU_MUST="$(get ...


1

Using the lsb_release command (should be in most distros by default): shopt -s nocasematch if [ -x "$(which lsb_release)" ]; then case "$(lsb_release -si)" in *centos*) case "$(lsb_release -sr)" in 5.7*) source ~/.bashrc.centos5.7 ;; 5*) # source something for any other version 5 minor release ...


2

I realize you mentioned not to edit .bashrc. However, I hope this might help someone else. I have been looking for a good answer to a similar problem for many years. I like to use vi but don't want to change the default for everyone else. Edit /etc/ssh/ssh_config in your local configuration and add the following line: SendEnv EDITOR You can use any ...


6

No, there isn't. Yes, this is a design defect. Use the following content in ~/.bash_profile: if [ -e ~/.profile ]; then . ~/.profile; fi if [[ -e ~/.bashrc && $- = *i* ]]; then . ~/.bashrc; fi Beware that bash has an even weirder quirk: when it is a non-interactive login shell and the parent process is rshd or sshd, bash sources ~/.bashrc (but ...


-1

There are several files that run when you login to your shell including ~/.bash_profile and possibly ~/.bashrc and ~/.bash_aliases if those are referenced in your ~/.bash_profile file. To have an alias available every time you login, just put the command that creates the alias in one of those files. ...


2

Here is my workaround, the function palias (aka permanent alias): function palias () { if [ $# -ne "2" ] ; then error "Usage: palias short-alias \"long-alias\"" return fi alias $1="$2" echo -e "alias $1='$2'" >> ~/.bash_aliases }


3

The Arch Wiki has some example aliases and generic commands that will work in the majority of .bashrc files providing you are using systemd and have sudo installed. This highlights the problem with the approach you are seeking, and one of the undesirable side effects of copying and pasting someone else's idea of a standard configuration into your shell 's ...



Top 50 recent answers are included