Afficher un message
Vieux 30/05/2007, 05h15   #1
mowgli
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut shell script question - changing PS1 based on tty

I just made a simple shell script for changing the color username in
the PS1 prompt. The same commands if given one by one on the command
line, change the prompt as per the commands, all fine. But if the
script is executed, the prompt does not change. However the echo
statement is echoed fine and echo $? returns true.

Can someone check what is the problem with the script that these
commands execute fine on the CLI and not from inside the script?


Here's the script:

#!/bin/bash
# Purpose: To change prompt color based on tty number

# root's PS1, regardless of tty
ROOTPS='\[\]root\[\]:\[\]\w\[^[[00m\]$ '
# Colored PS1 based on tty number
TTY1PS='\[\]`whoami`\[^[[00m\]:\[\]\w\[\]$ '
TTY2PS='\[\]`whoami`\[^[[00m\]:\[\]\w\[\]$ '
TTY3PS='\[\]`whoami`\[^[[00m\]:\[\]\w\[\]$ '
TTY4PS='\[\]`whoami`\[^[[00m\]:\[\]\w\[\]$ '
TTY5PS='\[\]`whoami`\[^[[00m\]:\[\]\w\[\]$ '
TTY6PS='\[\]`whoami`\[^[[00m\]:\[\]\w\[\]$ '

if [ `echo $UID` = 0 ]
then
PS1=$ROOTPS # Set root's PS1

elif
[ `tty` = '/dev/tty1' ]
then
PS1=$TTY1PS
echo "You are on `tty`"

elif
[ `tty` = '/dev/tty2' ]
then
PS1=$TTY2PS
echo "You are on `tty`"

elif
[ `tty` = '/dev/tty3' ]
then
PS1=$TTY3PS
echo "You are on `tty`"

elif
[ `tty` = '/dev/tty4' ]
then
PS1=$TTY4PS
echo "You are on `tty`"

elif
[ `tty` = '/dev/tty5' ]
then
PS1=$TTY5PS
echo "You are on `tty`"

elif
[ `tty` = '/dev/tty6' ]
then
PS1=$TTY6PS
echo "You are on `tty`"

else
# This won't ever get echoed, or shouldn't.
echo "You are not a valid user of this system."
exit 1
fi



Regards,
mowgli

  Réponse avec citation
 
Page generated in 0,64180 seconds with 9 queries