LinuxQuestions.org
Visit Jeremy's Blog.
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 08-18-2010, 05:16 AM   #1
try-alls
Member
 
Registered: Dec 2009
Distribution: changes all the time
Posts: 79

Rep: Reputation: 15
how do i change "bash-4.1#" to "user@hostname


as title says really distro version is 13.1,
google has failed me an new to slack

many thanks in advance rev.dr.rich
 
Old 08-18-2010, 05:27 AM   #2
slackd
Member
 
Registered: Sep 2009
Location: Bangalore, India
Distribution: Fedora, Slackware, Arch Linux
Posts: 260
Blog Entries: 1

Rep: Reputation: 60
set PS1 variable in your .bashrc in ~/home/user directory

Code:
#---------------------
# Define a few Color's
#---------------------
BLACK='\e[0;30m'
BLUE='\e[0;34m'
GREEN='\e[0;32m'
CYAN='\e[0;36m'
RED='\e[0;31m'
PURPLE='\e[0;35m'
BROWN='\e[0;33m'
LIGHTGRAY='\e[0;37m'
DARKGRAY='\e[1;30m'
LIGHTBLUE='\e[1;34m'
LIGHTGREEN='\e[1;32m'
LIGHTCYAN='\e[1;36m'
LIGHTRED='\e[1;31m'
LIGHTPURPLE='\e[1;35m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
DARKGRAY='\e[01;30'
LIGHTGRAY='\e[00;37'
NC='\e[0m'              # No Color
# Sample Command using color: echo -e "${CYAN}This is BASH

PS1="\[\033[35m\]\[\033[36m\]\w\n\[\033[0;31m\]\u@\h\[\033[1;34m\] ~\[\e[1;32m\]> \[\e[m\]\[\e[0;37m\]\[\033[0m\]"
The above text code will give you the desired prompt!

Last edited by slackd; 08-18-2010 at 05:33 AM.
 
Old 08-18-2010, 05:32 AM   #3
bonaire
Member
 
Registered: Jun 2008
Location: Bonn/Germany
Distribution: Slackware-13.37
Posts: 94

Rep: Reputation: 19
better readable:

Code:
function set_prompt () {
  local GRAY="\[\033[1;30m\]"
  local LIGHT_GRAY="\[\033[0;37m\]"
  local CYAN="\[\033[0;36m\]"
  local LIGHT_CYAN="\[\033[1;36m\]"
  local NO_COLOUR="\[\033[0m\]"
  local BLUE="\[\033[0;34m\]"
  local LIGHT_BLUE="\[\033[1;34m\]"
  local RED="\[\033[0;31m\]"
  local LIGHT_RED="\[\033[1;31m\]"
  local GREEN="\[\033[0;32m\]"
  local LIGHT_GREEN="\[\033[1;32m\]"
  local PURPLE="\[\033[0;35m\]"
  local LIGHT_PURPLE="\[\033[1;35m\]"
  local BROWN="\[\033[0;33m\]"
  local YELLOW="\[\033[1;33m\]"
  local BLACK="\[\033[0;30m\]"
  local WHITE="\[\033[1;37m\]"
  # PS1="$LIGHT_GREEN\u $YELLOW[$RED\w$YELLOW] $LIGHT_BLUE(\$(date +%H:%M:%S))$NO_COLOUR: "
  # PS1="$LIGHT_GREEN\u $YELLOW[$RED\w$YELLOW]$NO_COLOUR "
  PS1="\u@\h "
}
set_prompt
 
Old 08-18-2010, 05:32 AM   #4
sahko
Senior Member
 
Registered: Sep 2008
Distribution: Slackware
Posts: 1,041

Rep: Reputation: Disabled
You might want to read /usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO
 
Old 08-18-2010, 07:43 AM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: SlackwareŽ
Posts: 13,609
Blog Entries: 34

Rep: Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790Reputation: 2790
Hi,
Since you want to modify '.bashrc' then you could setup a .bashrc & .bash_profile for your user. Just modify the PS1 to suit;

Code:
sample .bash_profile;
Code:
 
 ~$ 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!
Bash Reference Manual &
Advanced Bash-Scripting Guide along with Rute Tutorial & Exposition should provide additional help.

 
Old 08-18-2010, 03:58 PM   #6
try-alls
Member
 
Registered: Dec 2009
Distribution: changes all the time
Posts: 79

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by sahko View Post
You might want to read /usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO
wow why didn't i know of these before, lol
 
Old 08-18-2010, 04:18 PM   #7
try-alls
Member
 
Registered: Dec 2009
Distribution: changes all the time
Posts: 79

Original Poster
Rep: Reputation: 15
ok, to be honest i don't understand how the provided codes can change bash to user@... please can someone run it by me as it seems this only colourises the terminal to which i have got it coloured already."god i've got to use to babysitting distro's like ubuntu, lol"

Last edited by try-alls; 08-18-2010 at 05:47 PM. Reason: typo's, readability
 
Old 08-18-2010, 08:56 PM   #8
slackd
Member
 
Registered: Sep 2009
Location: Bangalore, India
Distribution: Fedora, Slackware, Arch Linux
Posts: 260
Blog Entries: 1

Rep: Reputation: 60
Code:
PS1="\[\033[35m\]\[\033[36m\]\w\n\[\033[0;31m\]\u@\h\[\033[1;34m\] ~\[\e[1;32m\]> \[\e[m\]\[\e[0;37m\]\[\033[0m\]"
^Look carefully at the line above, this will help you understand-

Quote:
When executing interactively, bash displays the primary
prompt PS1 when it is ready to read a command, and the
secondary prompt PS2 when it needs more input to complete
a command. Bash allows these prompt strings to be cus-
tomized by inserting a number of backslash-escaped special
characters that are decoded as follows:

\a an ASCII bell character (07)
\d the date in "Weekday Month Date" format
(e.g., "Tue May 26")
\e an ASCII escape character (033)
\h the hostname up to the first `.'
\H the hostname
\n newline
\r carriage return
\s the name of the shell, the basename of $0
(the portion following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchlevel
(e.g., 2.00.0)
\w the current working directory
\W the basename of the current working direc-
tory
\! the history number of this command
\# the command number of this command
\$ if the effective UID is 0, a #, otherwise a
$
\nnn the character corresponding to the octal
number nnn
\\ a backslash
\[ begin a sequence of non-printing characters,
which could be used to embed a terminal con-
trol sequence into the prompt
\] end a sequence of non-printing characters

Last edited by slackd; 08-18-2010 at 08:58 PM.
 
Old 08-18-2010, 08:58 PM   #9
ax25nut
Member
 
Registered: Mar 2010
Location: Fairfield County, Ohio
Distribution: Several flavors of Linux, BSD Unix, even DOS & Win-doze
Posts: 56
Blog Entries: 1

Rep: Reputation: 19
aargh!

nuts. I goofed. can someone delete this post?

Last edited by ax25nut; 08-18-2010 at 09:09 PM.
 
Old 08-18-2010, 09:06 PM   #10
ax25nut
Member
 
Registered: Mar 2010
Location: Fairfield County, Ohio
Distribution: Several flavors of Linux, BSD Unix, even DOS & Win-doze
Posts: 56
Blog Entries: 1

Rep: Reputation: 19
You could try setting the hostname like this: hostname <newname> <rtn>

Then you can add users like this: adduser <myusername> <rtn>

Of course, you can also do it as posted above, but this always seemed easier to me than digging out a file and editing it. When adding usernames, you'll likely get a menu of things to add or do. If you don't know what you're doing at the command line with this, you can garf something up pretty quick, but re-installing hasn't ever been a big deal to me, as I do this just to fiddle with things here. After executing these two commands, you should re-boot. You'll then see your login with your new hostname.
 
Old 08-19-2010, 01:31 AM   #11
try-alls
Member
 
Registered: Dec 2009
Distribution: changes all the time
Posts: 79

Original Poster
Rep: Reputation: 15
i already have users an hostname set up but they do not display on my terminal.
 
Old 08-19-2010, 01:33 AM   #12
try-alls
Member
 
Registered: Dec 2009
Distribution: changes all the time
Posts: 79

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by slackd View Post
Code:
PS1="\[\033[35m\]\[\033[36m\]\w\n\[\033[0;31m\]\u@\h\[\033[1;34m\] ~\[\e[1;32m\]> \[\e[m\]\[\e[0;37m\]\[\033[0m\]"
^Look carefully at the line above, this will help you understand-
ah u@h makes sense, lol cool so seems "easy enough" open bashrc in preferred text editor an add this line,

EDIT; i didn't have a bash rc so created a new one wih your provided code an was intending to edit the colour but even better the colour work nicely with my "terminal-colours" theme an as asked my prompts are back to something i can use (not knowing which terminal was in root at the time was most confusing,
thankyou

Last edited by try-alls; 08-20-2010 at 10:42 AM. Reason: typo's
 
Old 08-20-2010, 02:20 AM   #13
ChrisAbela
Member
 
Registered: Mar 2008
Location: Malta
Distribution: Slackware and Debian
Posts: 560

Rep: Reputation: 138Reputation: 138
This is all you need:

Quote:
chris@office:~$ cat .bashrc
#!/bin/sh
if [ -r /etc/profile ] ;then
. /etc/profile
fi
Copy this .bashrc in /etc/skel so that all the future users that you define will inherit it automatically.
 
Old 08-20-2010, 08:12 AM   #14
dTd
Member
 
Registered: Feb 2007
Location: CT, USA
Distribution: Slackware
Posts: 99

Rep: Reputation: 11
PS1='[\u@\h:\W]\$ '

short, simple, informative.
 
Old 08-20-2010, 10:46 AM   #15
try-alls
Member
 
Registered: Dec 2009
Distribution: changes all the time
Posts: 79

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by ChrisAbela View Post
This is all you need:



Copy this .bashrc in /etc/skel so that all the future users that you define will inherit it automatically.
i don't think i will be creating any more users, unless the mrs decides she wants one (no dirty comments on the please lol) but i will keep note of this.

i have just downloaded the o'reilly bash quick reference an so far have the first 18 pages printed out, so fingers crossed i may be able (eventually) to make possibly usefull scripts to be shared.

also i like you signature.

Last edited by try-alls; 08-20-2010 at 10:48 AM.
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Hostname defined in file "network" changes after change to file "hosts" qwkfish Linux - Networking 2 10-14-2009 04:07 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
How to change prompt hostname "localhost"? Arodef Fedora 3 08-02-2004 06:45 AM
bash-2.05b# Xlib: extension "XFree86-DRI" missing on display ":0.0". citrus Linux - General 8 02-22-2004 10:43 AM

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

All times are GMT -5. The time now is 05:58 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
Open Source Consulting | Domain Registration