[SOLVED] Setting $PS1 Variable
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2018
    Location
    Port CoQuitlam, BC
    Posts
    17
    Linux (Fedora) Firefox 64.0

    Question Setting $PS1 Variable

    My terminal is showing bash 4.4 I understand why. The $PS1 variable is defaulting to \s-\v\$ as per

    Click image for larger version. 

Name:	Screenshot from 2019-01-12 14-17-31.png 
Views:	11 
Size:	21.9 KB 
ID:	29989

    My results as per grep $USER /etc/passwd and grep PS1 /etc/bashrc |

    Click image for larger version. 

Name:	Screenshot from 2019-01-12 14-25-32.png 
Views:	9 
Size:	5.5 KB 
ID:	29991

    What specific syntax do I use to set my $PS1 variable? Do I simply change \s-\v\$ to orcacomputers | ?


    I referenced the two threads attached, but am still struggling with specifically what to type. <--- white belt penguin



    Thread 1|
    Thread 2|
    Attached Images Attached Images  

  2. #2
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,875
    Linux Chrome 71.0.3578.98

    Re: Setting $PS1 Variable

    Is your ~/.bashrc file intact? That file generally references the /etc/bashrc file which sets the defaults, including the terminal command prompt style. Look at the /etc/bashrc file to get an idea how it sets the prompt string.

    Here is my terminal prompt and the $PS1 that sets it.
    Code:
    [paul@fettel ~]$ echo $PS1
    [\u@\h \W]\$
    That's username@host working_directory dollar_sign
    Last edited by PabloTwo; 13th January 2019 at 01:35 AM.

  3. #3
    Join Date
    Dec 2018
    Location
    Port CoQuitlam, BC
    Posts
    17
    Linux (Fedora) Firefox 64.0

    Re: Setting $PS1 Variable

    Sorry I forgot to mention, looks like ~/.bashrc is configured correctly, unless I am missing something. Here is the output,

    bash-4.4$ cat ~/ .bashrc
    cat: /home/orcacomputers/: Is a directory
    # .bashrc

    # Source global definitions
    if [ -f /etc/bashrc ]; then
    . /etc/bashrc
    fi

    # User specific environment
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
    export PATH

    # Uncomment the following line if you don't like systemctl's auto-paging feature:
    # export SYSTEMD_PAGER=

    # User specific aliases and functions

  4. #4
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,875
    Linux Chrome 71.0.3578.98

    Re: Setting $PS1 Variable

    Looks proper to me and comparable to mine.

  5. #5
    Join Date
    Jun 2005
    Location
    Montreal, Que, Canada
    Posts
    5,612
    Linux (Fedora) Firefox 63.0

    Re: Setting $PS1 Variable

    I don't think you need in the .bashrc or the .bash_profile.
    the two dirs are filled in by a higher level profile when you log into the system,
    Comment it out and verify.

    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
    export PATH

    As for $PS1

    Code:
    cat setPS1.sh 
    #!/bin/bash
    #  Place this script within /etc/profile.d
    #
    BRed='\[\e[1;31m\]'
    BYel='\[\e[1;33m\]'
    BWhi='\[\e[1;37m\]'
    #Whit='\[\e[0;37m\]'
    #Blue='\[\e]0;36m\]'
    
    if [ $EUID = 0 ];
    then
    export PS1="${BRed}\u\[\e[1;37m\]@\[\e[1;32m\]\h \[\e[1;36m\]\W\[\e[1;37m\]]\[\e[0;37m\]\$ " 
    else
    export PS1="${BYel}\u\[\e[1;37m\]@\[\e[1;36m\]\h \[\e[1;32m\]\W\[\e[1;37m\]]\[\e[0;37m\]\$ " 
    fi
    Leslie in Montreal

    Interesting web sites list
    http://forums.fedoraforum.org/showth...40#post1697840

  6. #6
    Join Date
    Dec 2018
    Location
    Port CoQuitlam, BC
    Posts
    17
    Linux (Fedora) Firefox 64.0

    Re: Setting $PS1 Variable

    I just commented the lines out, rebooted and not the file is gone lol, is that bad? Did I just create a new problem? How do I revert or add the file back?

    I added the script rebooted, still have bash-4.4$ See attachment.
    Click image for larger version. 

Name:	Screenshot from 2019-01-12 23-20-13.png 
Views:	8 
Size:	11.0 KB 
ID:	29992

  7. #7
    Join Date
    Apr 2018
    Location
    Finland
    Posts
    111
    Linux Chrome 71.0.3578.98

    Re: Setting $PS1 Variable

    I might be missing something but why don't you just add "PS1=[\u@\h \W]\$" (or what ever you want as yous $PS1) to ~/.bashrc and then run command "source ~/.bashrc" (or ". ~/.bashrc" if you want to type less)?

  8. #8
    PabloTwo's Avatar
    PabloTwo is offline "Registered User" T-Shirt Winner
    Join Date
    Mar 2007
    Location
    Seville, FL
    Posts
    7,875
    Linux Chrome 71.0.3578.98

    Re: Setting $PS1 Variable

    Quote Originally Posted by PabloTwo
    Looks proper to me and comparable to mine.
    Well, except for the fact that setting PATH should be in your ~/.bash_profile file and not in the .bashrc file.

  9. #9
    Join Date
    Dec 2018
    Location
    Port CoQuitlam, BC
    Posts
    17
    Linux (Fedora) Firefox 64.0

    Red face Re: Setting $PS1 Variable

    Comment it out and verify.

    I did this and now the .bash_profile and .bashrc file no longer exist. wtf!? *scratches head*
    Anyone know the reason for that? I figured if I commented the two lines out I could test and uncomment to go back to default settings.

    I have copy pasted the backup .bash_profile and .bashrc file from /etc/skel and pasted that syntax into a new .bash_profile in my home directory,

    So now I have the default settings.
    Last edited by themepenguin; 13th January 2019 at 07:36 PM.

  10. #10
    Join Date
    Jun 2005
    Location
    Montreal, Que, Canada
    Posts
    5,612
    Linux (Android 9) Chrome 71.0.3578.99

    Re: Setting $PS1 Variable

    By commenting put a line, you do not delete it. You just put # as the first character.

    And of course, to uncomment a line you remove the # character.
    Leslie in Montreal

    Interesting web sites list
    http://forums.fedoraforum.org/showth...40#post1697840

Similar Threads

  1. setting an session shell variable in script
    By nickdu in forum Using Fedora
    Replies: 3
    Last Post: 25th August 2015, 03:46 AM
  2. setting an environment variable
    By daviddoria in forum Using Fedora
    Replies: 5
    Last Post: 28th June 2008, 12:42 AM
  3. Need help setting path variable for QT4
    By geeare1 in forum Using Fedora
    Replies: 0
    Last Post: 23rd August 2006, 03:07 AM
  4. Setting an environment variable
    By rob2000007 in forum Using Fedora
    Replies: 3
    Last Post: 22nd November 2005, 10:36 PM
  5. Setting glib environment variable
    By keithcybin in forum Using Fedora
    Replies: 2
    Last Post: 10th June 2005, 11:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •