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