DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 19th January 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,116
Thanked 182 Times in 149 Posts
Default OpenBSD: modify .profile for PS1 and PAGER

A small script to modify PS1 and PAGER
Code:
# ---------------------------------------------------------
 
# /.profile used to be a  hard link to /root/.profile so only one needed
# to be modified
# Not true anymore :

#  ls -il /.profile /root/.profile 
#   24 -rw-r--r--  1 root  wheel  411 Jan 15 22:33 /.profile
# 4182 -rw-r--r--  1 root  wheel  440 Jan 18 01:13 /root/.profile

PROFILES="/.profile /root/.profile /etc/skel/.profile"

echo Modifying PS1 in ${PROFILES}

for file in $PROFILES ; do
    echo "$0: adding prompt to: $file"
    cat <<-END >>$file

        # --- prompt
        # j65nko@zeno[/home/j65nko/] 
        #  \u   @ \h [    \w       ]

        PS1="\u@\h[\w]"
        export PS1
        export PAGER=/usr/bin/less
END
done
The script uses the here document construct. From the OpenBSD (k)sh man page:
Code:
     << marker
             After reading the command line containing this kind of redirec-
             tion (called a ``here document''), the shell copies lines from
             the command source into a temporary file until a line matching
             marker is read.  When the command is executed, standard input is
             redirected from the temporary file.  If marker contains no quoted
             characters, the contents of the temporary file are processed as
             if enclosed in double quotes each time the command is executed,
             so parameter, command, and arithmetic substitutions are per-
             formed, along with backslash (`\') escapes for `$', ``', `\', and
             `\newline'.  If multiple here documents are used on the same com-
             mand line, they are saved in order.

     <<- marker
             Same as <<, except leading tabs are stripped from lines in the
             here document.
The marker used is '-END' so the leading tabs will be stripped.
You only have to use this when you want the here document to align nicely inside a loop like here.
Be aware that this only strips leading tabs and not leading spaces.

You can verify with cat whether there are really tabs and not spaces
Code:
$ cat -nt
    [snip] 
    15  for file in $PROFILES ; do
    16      echo "$0: adding prompt to: $file"
    17      cat <<-END >>$file
    18  
    19  ^I# --- prompt
    20  ^I# j65nko@zeno[/home/j65nko/] 
    21  ^I#  \u   @ \h [    \w       ]
    22  
    23  ^IPS1="\u@\h[\w]"
    24  ^Iexport PS1
    25  ^Iexport PAGER=/usr/bin/less
    26  END
    27  done
The CNTRL-I's (^I) proves that there are indeed leading tabs.

If you past the scirpt, then those tabs usually disappear:
Code:
$ cat -net pasted
     1  $
     2  for file in $PROFILES ; do$
     3      echo "$0: adding prompt to: $file"$
     4      cat <<-END >>$file$
     5  $
     6          # --- prompt$
     7          # j65nko@zeno[/home/j65nko/] $
     8          #  \u   @ \h [    \w       ]$
     9  $
    10          PS1="\u@\h[\w]"$
    11          export PS1$
    12          export PAGER=/usr/bin/less$
    13  END$
The .profile in the "/etc/skel" directory usually will be copied into the home directory of each user account.
Code:
# ls -l /etc/skel 
-rw-r--r--  1 root  wheel   22 Jan 15 22:33 .Xdefaults
-rw-r--r--  1 root  wheel  773 Jan 15 22:33 .cshrc
-rw-r--r--  1 root  wheel  398 Jan 15 22:33 .login
-rw-r--r--  1 root  wheel  113 Jan 15 22:33 .mailrc
-rw-r--r--  1 root  wheel  265 Jan 18 05:02 .profile
drwx------  2 root  wheel  512 Jan 15 22:33 .ssh
By customizing this file and/or the others, before creating user accounts you save time and efforts. Proactive laziness
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 19th January 2010 at 01:50 AM. Reason: Enlarged fornt for "<< marker" and "<<-marker"
Reply With Quote
  #2   (View Single Post)  
Old 20th January 2010
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Thanked 112 Times in 104 Posts
Default

My way of being lazy, is simply called git.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote
Reply

Tags
.profile, /etc/skel, here document, ps1 prompt

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify the ls command? bsdnewbie999 OpenBSD General 9 16th May 2009 08:20 AM
read & modify files out side chroot jail Dr_Death_UAE FreeBSD Security 5 6th November 2008 09:20 PM
Modify host-level firewall rules (without getting locked out) anomie Guides 13 16th June 2008 04:26 AM
Which light Gui from modify images files? aleunix OpenBSD General 7 15th June 2008 04:32 PM
How to modify the boot loader? Sunsawe FreeBSD General 5 29th May 2008 05:13 AM


All times are GMT. The time now is 11:34 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick