LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-19-2016, 07:51 PM   #1
cezarrangel
Member
 
Registered: Dec 2011
Posts: 77

Rep: Reputation: Disabled
.bashrc file: have or do not have?


hi guys is it really necessary and worth having a .bashrc file in Slack to improve it?
 
Old 07-19-2016, 07:59 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Define "improve".

The bash invocation configs are just an option that you can use, or not use, to best suit your own needs.

What needs do you have that are not met by the basic system?
 
Old 07-19-2016, 08:12 PM   #3
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Necessary? No. Worth having? Depends.

It's more likely that you'd want stuff in your ~/.bash_profile, which is read on login sessions. ~/.bashrc is read by every invocation of bash by your userid, which may have side effects.
 
Old 07-20-2016, 12:37 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
you may want to read man bash, look for invocation. It will explain how it is used. Also you may google for typical usage and ideas about it
 
Old 07-20-2016, 01:00 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,574
Blog Entries: 19

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
I find it useful for setting up aliases for commands.
 
Old 07-20-2016, 08:58 AM   #6
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member response

Hi,

Quote:
Originally Posted by cezarrangel View Post
hi guys is it really necessary and worth having a .bashrc file in Slack to improve it?
I do like the utility for a user to have a '.bashrc' file;
Code:
~$ cat .bashrc
#.bashrc
#08-30-06 12:20 gws copied loki:/root

# 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 listlong='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 gws

#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
I really find my easily modified alias within .bashrc by users to have the alias helpful when working at the cli. This is a very good way to utility work at the cli via alias. Not really improving Slackware but the environment for a user at the terminal/console.

Try it, you may like it!

Hope this helps.
Have fun & enjoy!
 
3 members found this post helpful.
Old 07-20-2016, 10:00 AM   #7
drgibbon
Senior Member
 
Registered: Nov 2014
Distribution: Slackware64 15.0
Posts: 1,220

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by cezarrangel View Post
hi guys is it really necessary and worth having a .bashrc file in Slack to improve it?
It probably depends how much you use the command line. At a minimum you could improve the prompt (make it more informative, or just more visually appealing), and you could also define aliases that are useful to you. You can see an example of a zsh configuration in action here, although similar things could be achieved in bash I suppose.
 
1 members found this post helpful.
Old 07-20-2016, 11:59 AM   #8
ttk
Senior Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 1,038
Blog Entries: 27

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Mine looks a lot like onebuck's, except that mine eradicates color rather than adding it, and adds these to revert character-handling to saner, simpler ASCII (which is incidentally faster for some standard utilities like grep(1) and sort(1)), asserts the POSIXy behavior to which I have become accustomed, and formats my shell history file usefully:

Code:
export LANG=C
export LC_ALL=C
export _POSIX2_VERSION=199209
export XTERM_LOCALE=C
export HISTTIMEFORMAT='%F %T'
export HISTFILESIZE=10000
export HISTSIZE=10000
ETA: Having both LANG and LC_ALL set is redundant (LANG sets the default for when some LC_* is not set, and LC_ALL overrides the settings of all LC_*) but I like to set them both anyway, for reasons.

Last edited by ttk; 07-24-2016 at 11:12 AM.
 
1 members found this post helpful.
Old 07-20-2016, 02:31 PM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,849

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
exported variables fit better into ~/.profile
 
Old 07-20-2016, 03:05 PM   #10
Gerardo Zamudio
Member
 
Registered: Jan 2011
Distribution: Slackware
Posts: 128

Rep: Reputation: 112Reputation: 112
Some people like using Slackware's default profile. If you load it in ~/.bashrc you get a nice prompt when using a desktop environment:

Code:
gzamudio@hades:~ $ cat ~/.bashrc
. /etc/profile
Instead of the default :
Code:
bash-4.3$
Personally, I have this in /etc/profile to get a red prompt for root and to make the prompt look nice. I also need ssh-agent loaded. I forget where I lifted most of this from. Probably some CentOS configuration file.

Code:
# If id command returns zero, you've root access.
if [ $(id -u) -eq 0 ];
then # you are root, set red colour prompt
PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w # \\[$(tput sgr0)\\]"
else # normal
PS1="\\u@\\h:\\w $ "
fi

# Set global aliases
alias ..="cd .."
alias ...="cd ../.."
alias ll="ls -lh"

SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
	eval `$SSHAGENT $SSHAGENTARGS`
	trap "kill $SSH_AGENT_PID" 0
fi
 
Old 07-20-2016, 05:10 PM   #11
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Code:
function set_prompt {
    # Must come first!
    local last_command=$?
    PS1=""
    local blue='\[$(tput setaf 4)\]'
    local white='\[$(tput setaf 7)\]'
    local red='\[$(tput setaf 1)\]'
    local green='\[$(tput setaf 2)\]'
    local reset='\[$(tput sgr0)\]'
    local fancyX='\342\234\227'
    local checkmark='\342\234\223'

    PS1+="$white$last_command "
    if [[ $last_command == 0 ]]; then
        PS1+="$green$checkmark "
    else
        PS1+="$red$fancyX "
    fi
    if [[ $EUID == 0 ]]; then
        PS1+="$red\\h "
    else
        PS1+="$green\\u@\\h "
    fi
    PS1+="$blue\\w \\\$$reset "
}
# jenv will add a hook at the front if we don't preempt that.
function _jenv_export_hook {
   local do_nothing
}
PROMPT_COMMAND='set_prompt;_jenv_export_hook'
If you don't use the jenv export plugin (which is probably 99.99% of you), you can remove the _jenv_export_hook in its entirety from the above bit. I do use the jenv export plugin and it took me a while to figure out why my red x on errors disappeared. (In fact, it was while I was composing the post to ask people here if they could figure it out that I figured it out.)

That code's not original to me; someone else in this forum posted a link to the original version. I've changed it to use tput, which required another slight change to preserve the old error code before running the tput command to build the prompt.
 
2 members found this post helpful.
Old 07-20-2016, 05:24 PM   #12
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
I'll also add that you can use a bash function instead of an alias, if you wish. Functions tab-complete like aliases but they allow you to add parameters, which aliases do not.

At work, I've got a bunch of servers in our staging environment to which I need the ssh into during the day. Instead of creating a bunch of aliases (one for each server), I created a bash function that takes the server type and server number and concatenates the two together to create and execute the ssh command.
 
1 members found this post helpful.
Old 07-21-2016, 09:16 AM   #13
Gerardo Zamudio
Member
 
Registered: Jan 2011
Distribution: Slackware
Posts: 128

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by Richard Cranium View Post
At work, I've got a bunch of servers in our staging environment to which I need the ssh into during the day. Instead of creating a bunch of aliases (one for each server), I created a bash function that takes the server type and server number and concatenates the two together to create and execute the ssh command.
Would you mind sharing that?

I have a similar situation at work. I SSH into about a hundred servers on a daily basis and the hostnames consist of [a-z][0-9].sub.domain.com.
 
Old 07-21-2016, 02:24 PM   #14
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by Gerardo Zamudio View Post
Would you mind sharing that?

I have a similar situation at work. I SSH into about a hundred servers on a daily basis and the hostnames consist of [a-z][0-9].sub.domain.com.
Sure!

Here's a variation of what I do.
Code:
# $1 is the shortname of the server
function go_server {
  go_server_user ${USER} ${1}
}


# $1 is the user to use
# $2 is the shortname of the server
function go_server_user {
   ssh ${1}@${2}.sub.domain.com
}
If you are going to some server as yourself go_server <shortname>. If you are going to some server as another user, go_server_user <user> <shortname> If you type go and hit the tab key, you should get both commands as possible completions. (Plus whatever else might match.)

If some of your servers are special in some way, you can change go_server_user to handle it...
Code:
# $1 is the user to use (maybe)
# $2 is the shortname of the server
function go_server_user {
   case ${2} in
     "z*")
        # fred is the only user allowed on z machines
        ssh fred@${2}.sub.domain.com
     ;;
     *)
        ssh ${1}@${2}.sub.domain.com
   esac
}
 
2 members found this post helpful.
Old 07-22-2016, 08:01 AM   #15
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
For those using tput, is there a benefit to using that instead of bash color codes? For my prompt, I change the color of my computer names so I can easily realize which machine I'm currently logged into (I do a lot of ssh sessions between various machines) and I highlight the root user in red.

Code:
# Regular user's prompt
PS1='\u@\e[35m\h\e[0m:\w\$ '
# Root's prompt
PS1='\e[41m\u\e[49m@\e[35m\h\e[0m:\w\$ '
As to the original question about a .bashrc, I don't use one. Since I'm the only user on my machines, I just modify /etc/profile to make the few minor changes. Looking at my commit history, I added the sbin directories to regular user's $PATH, added the color to the prompts, and set my default VISUAL and EDITOR variables to nano (too lazy to learn vi/vim). I also modified /etc/profile.d/coreutils-dircolors.sh to add --group-directories-first to the LS_OPTIONS variable. However, if I was on a multi-user system, all of these changes would be in my .bashrc.

I also change konsole to use a login shell for every tab so I get all my customizations.
 
3 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bashrc file LinuxUser101 Linux - Newbie 4 04-14-2008 07:55 PM
Bashrc file Gins Linux - General 19 09-06-2005 03:19 PM
can't the file bashrc Paxmaster Linux - Software 10 01-02-2005 06:58 AM
where is the .bashrc file??? xenia Linux - Newbie 8 05-08-2004 12:11 PM
bashrc file Linvilidiot Linux - Newbie 3 03-11-2004 04:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration