LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   how do i change "bash-4.1#" to "user@hostname (https://www.linuxquestions.org/questions/slackware-14/how-do-i-change-bash-4-1-to-user%40hostname-826959/)

try-alls 08-18-2010 05:16 AM

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

slackd 08-18-2010 05:27 AM

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!

bonaire 08-18-2010 05:32 AM

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


sahko 08-18-2010 05:32 AM

You might want to read /usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO

onebuck 08-18-2010 07:43 AM

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.


try-alls 08-18-2010 03:58 PM

Quote:

Originally Posted by sahko (Post 4070046)
You might want to read /usr/doc/Linux-HOWTOs/Bash-Prompt-HOWTO

wow why didn't i know of these before, lol

try-alls 08-18-2010 04:18 PM

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"

slackd 08-18-2010 08:56 PM

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


ax25nut 08-18-2010 08:58 PM

aargh!
 
nuts. I goofed. can someone delete this post?

ax25nut 08-18-2010 09:06 PM

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.

try-alls 08-19-2010 01:31 AM

i already have users an hostname set up but they do not display on my terminal.

try-alls 08-19-2010 01:33 AM

Quote:

Originally Posted by slackd (Post 4070780)
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

ChrisAbela 08-20-2010 02:20 AM

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.

dTd 08-20-2010 08:12 AM

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

short, simple, informative.

try-alls 08-20-2010 10:46 AM

Quote:

Originally Posted by ChrisAbela (Post 4072082)
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.

onebuck 08-20-2010 03:08 PM

Hi,

Here is some useful links;

SlackwareŽ Essentials
SlackwareŽ Basics
Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Newbie Admin Guide
LinuxSelfHelp
Getting Started with Linux

The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

bgrundy 08-20-2010 03:42 PM

I realize that this thread is already marked "solved", but for my own education...Is it possible that the OP was referring to an xterm and all that was needed is an option to run the terminal as a "login shell"?

For example, the preferences settings in xfterm4 General --> "Run command as Login Shell". The default prompt changes from "bash 4.1" to "user@host".

What did I miss? Is there a reason NOT to have xterms run as a login shell? (<---my real question).

try-alls 08-21-2010 01:24 AM

Quote:

Originally Posted by bgrundy (Post 4072742)
I realize that this thread is already marked "solved", but for my own education...Is it possible that the OP was referring to an xterm and all that was needed is an option to run the terminal as a "login shell"?

For example, the preferences settings in xfterm4 General --> "Run command as Login Shell". The default prompt changes from "bash 4.1" to "user@host".

What did I miss? Is there a reason NOT to have xterms run as a login shell? (<---my real question).

i was using the standard terminal for xfce and posted this as i could not find options for layout in the options tab

ChrisAbela 08-22-2010 03:33 AM

Quote:

What did I miss? Is there a reason NOT to have xterms run as a login shell? (<---my real question).
I know of no reason why not to use xterm as a login shell, but our solutions were aimed for all terminals, not just one in particular.


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