You are not logged in.

#1 2014-10-18 21:00:05

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

[Solved] Cannot "su" properly in a terminal due to a .bashrc error

The problem is simple:  I cannot su to my root account properly.  I can do so successfully in that I can become "root" but I get no output on the screen after typing in a command.  E.g., this is what my terminal shows after su'ing to root and typing the "ls" command:

: ~ : su
Password: 
:root:~: ls -a
:root:~: 

Even trying to bring up a nano window gives the same result:

:root:~: nano .bashrc
:root:~: 

I get this behaviour in RoxTerm but in Xfce-Terminal I get this error instead:

: ~ : su
Password: 
-bash: printf: write error: Broken pipe
Broken pipe (core dumped)
: ~ : 

I have received the same error in the past in RoxTerm but it seems to have gone away today.  I did Google that error but I found nothing that seemed to point to a solution for this issue.  And, after a lot of experimentation and troubleshooting, I've narrowed down my issue to an error in my .bashrc file.  However, despite combing through it several times, and finding other errors, I still can't locate what is causing this issue.

My .bashrc:

### ====== .bashrc + all prompts = a common config file for all ======
### Created Saturday 04 October 2014
## See [[ssh:ssh prompts]] for SSH 

# [[~/.bashrc]]

### Last edited October 2014 by H
#	===================================================================================================
# This file is sourced by all *interactive* bash shells on startup,			
# including some apparently interactive shells such as scp and rcp			
# that can't tolerate any output.  So make sure this doesn't display			
# anything or bad things will happen!							
#											
# If not running interactively, don't do anything.					
[[ $- != *i* ]] && return											

#	===================================================================================================
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

#	===================================================================================================
# Below are the color init strings for the basic file types. A color init string consists of one or more of the following numeric codes:

# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed

# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white

# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white

## Now source the .dir_colors file to use those colours!
if [ -x /usr/bin/dircolors ]; then
  test -r ~/.dir_colors && eval "$(dircolors -b ~/.dir_colors)" || eval "$(dircolors -b)"
fi

#	===================================================================================================
### [User Prompts]

## Very fancy ##
#export PS1='\[\033[0;32m\]┌┼─┼─ \[\033[0m\033[0;32m\]\u\[\033[0m\] @ \[\033[0;36m\]\h\[\033[0m\033[0;32m\] ─┤├─ \[\033[0m\]\t \d\[\033[0;32m\] ─┤├─ \[\033[0;34m\]\w\[\033[0;32m\] ─┤ \n\[\033[0;32m\]└┼─\[\033[0m\033[0;32m\]\$\[\033[0m\033[0;32m\]─┤▶\[\033[0m\] '

## Very fancy with $ removed 
#export PS1='\[\033[0;32m\]┌┼─┼─ \[\033[0m\033[0;32m\]\u\[\033[0m\] @ \[\033[0;36m\]\h\[\033[0m\033[0;32m\] ─┤├─ \[\033[0m\]\t \d\[\033[0;32m\] ─┤├─ \[\033[0;34m\]\w\[\033[0;32m\] ─┤ \n\[\033[0;32m\]└┼─\[\033[0;32m\]─┤▶\[\033[0m\] '

### White Yunzi
export PS1='\[\e[0;37m\]: \[\e[1;92m\]\W\[\e[0;37m\] :\[\e[m\] \[\e[0;37m\]'

#### Silver Yunzi
#export PS1='\[\e[0;37m\]: \[\e[1;94m\]\W\[\e[0;37m\] :\[\e[m\] \[\e[0;37m\]'

### Pink Yunzi
#export PS1='\[\e[0;37m\]: \[\e[1;95m\]\W\[\e[0;37m\] :\[\e[m\] \[\e[0;37\]'

#### Red Yunzi
#export PS1='\[\e[0;37m\]: \[\e[1;91m\]\W\[\e[0;37m\] :\[\e[m\] \[\e[0;37m\]'

### [Root Prompts]

###  White Yunzi Root
#export PS1='\[\e[1;37m\]:\[\e[1;92m\]\u\[\e[1;37m\]:\[\e[1;92m\]\W\[\e[1;37m\]:\[\e[m\] \[\e[0;37m\]'

### Silver Yunzi Root
#export PS1='\[\e[0;37m\]:\[\e[1;94m\]\u\[\e[0;37m\]:\[\e[1;94m\]\W\[\e[0;37m\]:\[\e[m\]\[\e[0;37m\]'

### Pink Yunzi Root
#export PS1='\[\e[0;37m\]:\[\e[1;95m\]\u\[\e[0;37m\]:\[\e[1;95m\]\W\[\e[0;37m\]:\[\e[m\] \[\e[0;37\]'

### Red Yunzi Root
#export PS1='\[\e[0;37m\]:\[\e[1;91m\]\u\[\e[0;37m\]:\[\e[1;95m\]\W\[\e[0;37m\]:\[\e[m\] \[\e[0;37\]'
#
# 	===========================================================================================================================================
### If the connection to the system is a remote connection 'ssh' will be
### appended to the prompt.  Otherwise the prompt will be displayed normally.	
# See:  remote.colourful.prompt_how-to on /media/lynwyn/networking/ssh		

#### White Yunzi ###

# : ~ : ssh :

if [ -n "$SSH_TTY" ] || [ -n "$SUDO_USER" ] ; then 
	PS1="$PS1"ssh\ :\ ""
fi
# 	================**OR**===========================================================================================================================
# : ~ : :ssh:

#export PS1='\[\e[0;37m\]: \[\e[1;92m\]\W\[\e[0;37m\] :\[\e[m\]\[\e[0;37m\]'

#if [ -n "$SSH_TTY" ] || [ -n "$SUDO_USER" ] ; then 
#	PS1="$PS1:ssh:"
#fi

# 	===========================================================================================================================================

### Silver Yunzi ### 
# :~::ssh:

#export PS1='\[\e[0;37m\]:\[\e[1;94m\]\W\[\e[0;37m\]:\[\e[m\]\[\e[0;37m\]'

#if [ -n "$SSH_TTY" ] || [ -n "$SUDO_USER" ] ; then			
#	PS1="$PS1":ssh: ""					
#fi
# 	===========================================================================================================================================

### Pink ###
# :~:ssh:

#export PS1='\[\e[0;37m\]:\[\e[1;95m\]\W\[\e[0;37m\]:\[\e[m\]\[\e[0;37m\]'
			
#if [ -n "$SSH_TTY" ] || [ -n "$SUDO_USER" ] ; then
#     PS1="$PS1"ssh: ""
#fi
# 	===========================================================================================================================================

### Red ###
# :~:ssh:

#export PS1='\[\e[0;37m\]:\[\e[1;91m\]\W\[\e[0;37m\]:\[\e[m\]\[\e[0;37m\]'
			
#if [ -n "$SSH_TTY" ] || [ -n "$SUDO_USER" ] ; then	
#     PS1="$PS1"ssh: ""
#fi

#	===================================================================================================
#### * BASH options * ###

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when it regains control.
# [check the window size after each command and, if necessary, update the values of LINES and COLUMNS.]
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

#	===================================================================================================
# automatically prepend cd when entering just a path in the shell
shopt -s autocd

#	===================================================================================================
# Enable history appending instead of overwriting.
shopt -s histappend

#	===================================================================================================
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000

#	===================================================================================================
## erase duplicate entries in your history file
## and force Bash History to ignorespace
export HISTCONTROL=erasedups:ignorespace

#	===================================================================================================
## This will prevent you from over-writing any file that you direct to with the ">" or ">>" symbols, thus destroying whatever pre-existing file
## you're pointing to in the first place.  This tweak prevents that from happening and ">" or ">>" will fail when directed at an existing file. 
## To clobber the existing file you have to use ">|" which is much harder to type by accident.
set -o noclobber
 	===========================================================================================================================================
## Set variable identifying the chroot you work in (used in the prompt below)
#if [ -z "$arch_chroot" ] && [ -r /etc/arch_chroot ]; then
#    debian_chroot=$(cat /etc/arch_chroot)
#fi

#	===================================================================================================
# environment variables using gedit and nano
export EDITOR="$(if [[ -n $DISPLAY ]]; then echo 'gedit'; else echo 'nano'; fi)"

#	===================================================================================================
### Colored output through environment variables
### Add the following lines to your shell configuration file @ ~/.bashrc:
### List of colors for prompt and Bash:  http://en.wikipedia.org/wiki/ANSI_escape_code#Colors
###  See the web page above for a complete listing of all the colours applicable to these environments:  
### Standard VGA colors / Windows XP CMD / Terminal.app / PuTTY / xterm / CSS/HTML / X 

#export LESS=-R
#export LESS_TERMCAP_me=$(printf '\e[0m')
#export LESS_TERMCAP_se=$(printf '\e[0m')
#export LESS_TERMCAP_ue=$(printf '\e[0m')
#export LESS_TERMCAP_mb=$(printf '\e[1;32m')
#export LESS_TERMCAP_md=$(printf '\e[1;34m')
#export LESS_TERMCAP_us=$(printf '\e[1;32m')
#export LESS_TERMCAP_so=$(printf '\e[1;44;1m')
# 
### Coloured man pages with explanations of colours in comments
# Note to self:  all of the colour & escape statements work ONLY by using double quote marks, e.g. " ... "
## Coloured man pages with explanations of colours in comments
# 67: Primary colour for program names is Dark Green [old 80's CRT green!]
# 68: Optional arguments and/or separate options for arguments is Bright Green
# 69: Text Reset
# 70: Text Reset
# 71: man page info bottom of page is Dark Red on Black background (net effect is transparent background with red writing)
# 72: Text Reset
# 73: References to other programs (and their respective man page(s)) are Bright Yellow [good neutral yellow]

man() {
	env LESS_TERMCAP_mb=$(printf "\e[1;31m") \
	LESS_TERMCAP_md=$(printf "\e[1;31m") \
	LESS_TERMCAP_me=$(printf "\e[0m") \
	LESS_TERMCAP_se=$(printf "\e[0m") \
	LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
	LESS_TERMCAP_ue=$(printf "\e[0m") \
	LESS_TERMCAP_us=$(printf "\e[1;32m") \
	man "$@"
}

#	===================================================================================================
## To get a skin of your choice loaded instead of mc's default
## skin, you might consider the following solution:
## Multi-User:  Create an alias for mc in your ~/.bashrc, like:
    if [ $TERM = "screen-256color" ]; then
        if [ $USER = "root" ]; then
            myMCSkin="modarcon16root-defbg"
        else
            myMCSkin="modarcon16-defbg"
        fi
        alias mc='mc --skin $myMCSkin'
        alias mcedit="mcedit --skin $myMCSkin"
        alias mcview="mcview --skin $myMCSkin"
        alias mcdiff="mcdiff --skin $myMCSkin"
    fi

#	===================================================================================================
# TMUX
# Put this this snippet BEFORE the aliases in .bashrc.
# This code starts TMUX with only one session (unless you start some manually), on login;
# it will try to attach to a currently running session.
# If there isn't a currently running session then TMUX will create one.
	# if which tmux 2>&1 >/dev/null; then
## if not inside a tmux session, and if no session is started start a new session
	# test -z "$TMUX" && (exec qterminal -e bash -c "tmux -q has-session && exec tmux attach-session -d || exec tmux new-session -n $USER -s $USER")
	# fi

#	===================================================================================================

Edit: fixed a few typos

Last edited by MoonSwan (2014-10-25 01:22:52)

Offline

#2 2014-10-18 21:23:54

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Solved] Cannot "su" properly in a terminal due to a .bashrc error

if [ -n "$SSH_TTY" ] || [ -n "$SUDO_USER" ] ; then 
	PS1="$PS1"ssh\ :\ ""
fi

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-10-25 01:22:29

MoonSwan
Member
From: Great White North
Registered: 2008-01-23
Posts: 881

Re: [Solved] Cannot "su" properly in a terminal due to a .bashrc error

Thank you very much for the response Jason and I am sorry for the late reply but as usual life got in the way.

I ended up doing some more experimentation and I did fix the bug you pointed out.  When this didn't solve the problem I started to look at other files.  It turned out that my .bash_aliases file was the real culprit.  The offending line was:

alias su='su -l | cd ~/' # invokes a login shell then changes to root's home directory 

I fixed the issue by changing that line to read:

 alias su='su -l ' # invokes a login shell then changes to root's home directory

As always thank you for the help,  smile

Offline

#4 2014-10-25 01:24:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Solved] Cannot "su" properly in a terminal due to a .bashrc error

Glad you got it sorted. smile


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB