LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2009, 08:00 PM   #1
babujd
LQ Newbie
 
Registered: Jul 2009
Posts: 6

Rep: Reputation: 0
Bash Profile ......


I am a newbie. Could some one please send me a sample .Bash_Profile file? I am just starting Linux and need to install oracle.
--- Babu
 
Old 07-17-2009, 08:16 PM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 5, Linux Lite
Posts: 4,312

Rep: Reputation: 208Reputation: 208Reputation: 208
Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME
Copy and paste to an empty text file, then save as .bash_profile
 
Old 07-17-2009, 08:22 PM   #3
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
Most stuff gets done in ~/.bashrc, but here's mine.
Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	source ~/.bashrc
fi

# User specific environment and startup programs

if [ -d $HOME/bin ]; then
        PATH=$PATH:$HOME/bin
        export PATH
fi

# Set me up to use passwordless SSH authentication.
ssh-agent > ~/.ssh-agent.sh
ssh_agent="$HOME/.ssh-agent.sh"
if [ -f $ssh_agent ]
then
  source $ssh_agent > /dev/null
fi
ssh-add

# Starting gpg-agent
if test ! -e ~/.gpg_agent_info; then
	gpg-agent --daemon --sh >>  ~/.gpg_agent_info
fi

unset USERNAME

Last edited by weibullguy; 07-17-2009 at 08:39 PM.
 
Old 07-20-2009, 12:53 PM   #4
babujd
LQ Newbie
 
Registered: Jul 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for the help in posting .bash_profile. Could you please let me know how to set the prompt to "home directory", that is, PS1 variable setting? The one that I used to on UNIX is not working here any more.
--- Babu
 
Old 07-20-2009, 01:01 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by babujd View Post
Thanks for the help in posting .bash_profile. Could you please let me know how to set the prompt to "home directory", that is, PS1 variable setting? The one that I used to on UNIX is not working here any more.
--- Babu
Please, post an example of what the prompt should be.
 
Old 07-20-2009, 01:35 PM   #6
babujd
LQ Newbie
 
Registered: Jul 2009
Posts: 6

Original Poster
Rep: Reputation: 0
I set the PS1 variable in .bashrc as follows to print the username & current working directory as prompt:

PS1="\u:\w>"

It is displaying as follows:

oracle:~>

I need "current working Directory" to be printed as prompt (Not ~). Could you please let me know how to set it?

--- Babu
 
Old 07-20-2009, 01:58 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Well... it is a shell behavior. The ~ indicates your home directory. I don't know how to get rid of it in the prompt, however when you change directory it should change to the current working directory name. Note that if you use \w the full path of the current working directory is displayed, while using \W (uppercase) just the name of the current directory is displayed.
 
Old 07-20-2009, 07:21 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Try this page: http://www.ibm.com/developerworks/li.../l-tip-prompt/
 
Old 07-20-2009, 07:55 PM   #9
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
In my ~/.bashrc file I have the following function
Code:
function localprompt()
{

	TITLEBAR='\[\033]0;\u@\h:\w\007\]'
	DASH="$bold_blue - "

	# Number of processes loaded.
	NUMPROCS="$bold_red\$(ps ax | wc -l | tr -d ' ') procs"

	# Number of files in current directory excluding links and hidden files.
	NUMFILES="$bold_red\$(ls -l | grep -v ^l | wc -l) files"

	# Number of bytes in the current directory (approximately anyway).
	DIRSIZE="$(ls --si -s | head -1 | awk '{print $2}') bytes"

	# Current directory at end of first line.
	CURDIR="$white\${PWD}\n"

	# User name.
	UNAME="$bold_red\u"

	# Short hostname (up to first '.')
	HOST="$bold_blue\h "

	# Ampersand.
	AMPERSAND="$white@"

	# Set the prompt symbol.
	PROMPT=" $white\$ "

	X="$(cat /proc/uptime) | awk '{print $1}')"
	Y=${X%%.*}
	secs=$((${Y}%60))
	mins=$((${Y}/60%60))
	hours=$((${Y}/3600%24))
	days=$((${Y}/86400))
	if [ "${days}" -ne "0" ]
	then
		UPTIME=" $white${days}D${hours}h${mins}m"
	else
		UPTIME=" $white${hours}h${mins}m"
	fi

	case $TERM in

		*term | rxvt)
			PS1="${NUMFILES}$white(\${DIRSIZE})${DASH}${CURDIR}${UNAME}${AMPERSAND}${HOST}for${UPTIME}${PROMPT}$britewhite"
			;;
		*)
			PS1="$red\u:\w\$ $britewhite"
			;;
	esac

	export PS1

}
This is what it looks like when in my $HOME (except it is in color)
Code:
49 files(5.8M bytes) - /home/andrew
andrew@aragorn for 8D19h55m $
I source a file called /etc/colors that simply assigns the color codes to variables that make more sense to me. For example
Code:
white="\033[1;37m"
Take a look here as well --> http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/
 
Old 07-21-2009, 05:25 PM   #10
babujd
LQ Newbie
 
Registered: Jul 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for all the help.This helps.

I am still a little bit uncomfortable using Bash shell on LINUX box at the moment OR until I learn the Bash shell.

Is it OK to set the default SHELL as K-SHELL(export SHELL=/bin/ksh) in the .profile, and use the K-Shell instead? OR Do we need to change the default Shell to "K-SHELL" from the Root directory or change it in /etc/bash_profile?

In other words, How to change the default shell permanently to K-SHELL for the entire LINUX Box?

--- Babu
 
Old 07-21-2009, 07:10 PM   #11
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,542
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

You could setup a .bashrc & .bash_profile for your user;

Code:
sample .bash_profile;

~$ cat .bash_profile
# .bash_profile
#08-30-06 12:21
#
# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
Code:
sample .bashrc;
:~$ cat .bashrc

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

# Add bin to path

export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"

#export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40

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`

# 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


The .bashrc is very useful!
 
Old 07-21-2009, 10:56 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
If you wan to use ksh (korn shell) as default, change the entry in /etc/passwd, its the last field.
http://www.cyberciti.biz/faq/underst...d-file-format/
The default 'profile' file would be in your home dir and called '.profile'. You can also create a .kshrc (equiv to .bashrc).
Check the file /etc/shells to ensure its in there: http://linux.die.net/sag/etc-fs.html
 
Old 07-22-2009, 03:39 AM   #13
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can change the shell of existing users by the chsh command. For newly created users, you can choose any shell listed in /etc/shells. The useradd command has options to choose the shell for the user and to change the predefined shell (see -D and -s).
 
Old 07-22-2009, 06:43 PM   #14
babujd
LQ Newbie
 
Registered: Jul 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks for the help. I have now changed the default shell to K-SHELL.
I have landed into another problem. ESC-K should display the previous command. It is not working anymore. ESC-K is displaying ^[ instead of displaying the previous command. Could you please help me how to make ESC-K working?

--- Babu
 
Old 07-22-2009, 06:47 PM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Have you tried the cursor keys, they should work ie be mapped to the old esc-k equivalents etc.
If you really want the old-style, try 'set -o vi'.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
screen bash profile? true_atlantis Linux - Software 3 06-26-2009 02:45 PM
Erasing the bash profile? AQG Linux - Security 6 07-06-2005 04:31 PM
bash and user profile maxoo Slackware 1 08-05-2004 07:19 AM
bash profile stuff gauge73 Linux - Newbie 7 01-05-2004 02:54 AM
where is my bash profile? bandofmercy Linux - General 3 04-08-2003 06:29 PM


All times are GMT -5. The time now is 04:26 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration