LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Slackware shell config help (https://www.linuxquestions.org/questions/slackware-14/slackware-shell-config-help-4175503766/)

hottdogg 05-02-2014 11:38 PM

Slackware shell config help
 
This is a simple problem but I just can't get my head around with :confused:.
Too stupid

Problem is I want to have my interactive shell(kde konsole) to have same 'more-colorful' like in login shell so I put /etc/profile in my .bashrc.
And I want login shell has same config as interactive shell.

Here's my ~/.bashrc
Code:

. /etc/profile #the dilemma line
alias grep='grep --color'
export GREP_COLOR=';32'
export APP_MODE='development'

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

my ~/.bash_profile
Code:

if [ -f ./.bashrc ]; then
    source ./.bashrc
fi

The problem with this is the fortune is run twice when I login through shell(I dont use gui login), because /etc/profile is invoked twice by login shell. And I don't want this,seems dirty and odd.

I put a diagram for you...
Code:

login-shell           
 ^        ^
 |          \
 |          \
.bash_profile \
 ^            /etc/profile
 |
 |
.bashrc
 ^
 |
 |
/etc/profile

interactive shell
  ^
  |
  |
.bashrc
  ^
  |
  |
/etc/profile

Can you guys give me advice for this?

Woodsman 05-02-2014 11:59 PM

When I had my web site running I had a nice how-to about harmonizing the bash scripts. If anybody is interested in moving that how-to the slackware.docs site, contact me and I'll forward the text.

In the mean time, try this:

Code:

# ~/.bash_profile
#
# Local/Personal aliases and functions go here
if [ -f $HOME/.bashrc ]; then
  source $HOME/.bashrc
fi

# Local/Personal startup programs go here

Code:

# ~/.bashrc
#
# System-wide aliases and functions go here
if [ -f /etc/bashrc ]; then
  source /etc/bashrc
fi

# Local/Personal environment variables go here
# Define bash prompts, non-X text editors, etc.
unset MAILCHECK

# --- Local aliases ---

# --- Local functions ---


wildwizard 05-03-2014 01:02 AM

You want Konsole to give you a shell like the one when you log in at boot?

Just change the setting in konsole

Settings -> Edit Current Profile
Change "Command:" from "/bin/bash" to "/bin/bash -ls"
Click Apply

The "-ls" on the end of the command tells bash you want to invoke it as if you were logging in and will execute the same scripts giving you the exact same environment.

Didier Spaier 05-03-2014 02:31 AM

Instead of sourcing /etc/profile, just cherry pick what you need in it and copy/paste that in ~/.bashrc. In addition, possibly run only (parts of) the scripts in /etc/profile.d that you need.

eloi 05-03-2014 07:51 AM

And Didier is right again.

It's the second time someone has the crazy idea of sourcing /etc/profile form
~/.bashrc

By the way. If you don't want the fortune message do this:

# chmod -x /etc/profile.d/bsd-games-login-fortune.sh


Jaime Sommers
Schoolteacher

tronayne 05-03-2014 08:07 AM

It's a Real Good Idea to leave /etc/profile alone; i.e., don't ever edit it (it's system-wide).

For customization, system-wide, you can add files to /etc/profile.d. For personal customization, you can add a ~/.profile file in your home directory and you can add ~/.bashrc file as well.

Now, why would you want to do things like that?

Well, the sequence when you log in is execute (in this order)
  • /etc/profile
  • /etc/profile.d/<files relevant to the shell program you're using and other executable files there>
  • /home/your_id/.profile
  • /home/your_id/.bashrc
At the bottom of /etc/profile, you'll find this:
Code:

# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
  if [ -x $profile_script ]; then
    . $profile_script
  fi
done
unset profile_script

That's what executes the stuff in /etc/profile.d. Some of those files are shell-specific (BASH, KornShell, C-Shell, etc.), some are system-wide (setting Java environment and the like).

All that happens once at log in and it happens when you open a terminal window as a "log in shell" which is what you typically want -- you get all the environment settings, aliases you like and all that sort of thing.

Hope this helps some.

onebuck 05-03-2014 08:22 AM

Member Response
 
Hi,

I like to provide my users with this;
Quote:


Code:

sample .bash_profile; 
~$ cat .bash_profile
#-----------------cut----------------- 
# .bash_profile
#08-30-06 12:21

# Source .bashrc
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

#-----------------cut end--------------


Code:

cat .bashrc
#-----------------cut-------------------

#.bashrc
#08-30-06 12:20

# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize
#
#save bash history so as to share

shopt -s histappend
PROMPT_COMMAND='history -a'

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
#08-29-06 11:40 gws
if [ `id -un` = root ]; then
PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
else
PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
#
# Add color
eval `dircolors -b`
#Terminus is a very nice Unicode font for the Linux console
#02-02-12 gws
#from dugan's site http://duganchen.ca/writings/slackware/fonts/

#04-30-12 11:41 removed
#
#if [ $TERM = "linux" ]; then
# setfont ter-v16n
#fi

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
 trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#trap 0 rm -f ~$LOGNAME/.bash_history


#-----------------cut end--------------


I let them modify to suit their needs.
Hope this helps!

eloi 05-04-2014 08:01 AM

Just for fun
 
Just for fun and off topic. This is my bash prompt.

Code:

function bg_jobs
{
        jobs | wc -l | grep -v 0 | sed "s/.*/[&]/"
}

PS1=''
case "$TERM" in
*xterm*|*rxvt*)
        # Window Title
        PS1+='\[\033]2;'
        PS1+='\w'
        PS1+='\007\]'
        # Icon Title
        PS1+='\[\033]1;'
        PS1+='\u@\h:\w'
        PS1+='\007\]'
        ;;
esac
PS1+='\u@\h:'
PS1+='\w'
PS1+='`bg_jobs`'
PS1+='\$ '

With this fashion you can intercalate stuff and colors in a clean way.


All times are GMT -5. The time now is 10:56 AM.