setting and displaying variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting setting and displaying variables
# 1  
Old 03-23-2011
setting and displaying variables

Hello, I need a little help.
1. Edit /etc/profile so that all users are greeted upon login.
2. For the root account, set the prompt to something like "Danger!! root is doing stuff in \w", preferably in a bright color such as red or pink or in reverse video mode.


Thanks for help.
# 2  
Old 03-23-2011
Is this homework?

/etc/profile is a shell script, so if you want to echo something, echo something. You can tell different users apart with the USER variable, if set. If it's not set, don't bother doing anything since you might be injecting 'Hi everybody!' into somebody's cron job or something equally pointless.
# 3  
Old 03-23-2011
Assuming this is unix.
The convention is to put the message in the file /etc/motd (Message of the Day).
Check your /etc/profile file because most of the manufacturer supplied versions of /etc/profile look for the Message of the Day file. Don't forget to undo the change when you have finished.

Change the root prompt at your own risk. Remember that whoever logs in as root may not be using the same type of terminal as you!
# 4  
Old 03-23-2011
No, it is not my homework. It is a bash practice problem from
Bash Guide for Beginners
I am using Linux fedora 14. I just want to improve myself.

Thanks.

---------- Post updated at 11:43 AM ---------- Previous update was at 11:35 AM ----------

How to modify profile?
Code:
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT good idea to change this file unless you know what you
# are doing. Much better way is to create custom.sh shell script in
# /etc/profile.d/ to make custom changes to environment. This will
# prevent need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`id -u`
        UID=`id -ru`
    fi
    USER="`id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi

HOSTNAME=`/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "$PS1" ]; then
            . $i
        else
            . $i >/dev/null 2>&1
        fi
    fi
done

unset i
unset pathmunge

# 5  
Old 03-23-2011
Please don't bump posts.
Quote:
Originally Posted by zhshqzyc
How to modify profile?
With a text editor like nano or vim. You'll need to su - into root to get sufficient privileges to edit it. But, reading this file:
Code:
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT good idea to change this file unless you know what you
# are doing. Much better way is to create custom.sh shell script in
# /etc/profile.d/ to make custom changes to environment. This will
# prevent need for merging in future updates.

...and this code:
Code:
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "$PS1" ]; then
            . $i
        else
            . $i >/dev/null 2>&1
        fi
    fi
done

...would suggest that you create a file under /etc/profile.d/ instead.

Try creating a /etc/profile.d/99-hello.sh file with this:

Code:
#!/bin/sh

echo "Hello, ${USER}"

and see if it works when you login. It should.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Displaying multiple variables in for loop

Hi! I've run into a problem where my variables are displayed in the wrong order. Basically I'm supposed to use a file that has information like this username:firstname:lastname:etc:etc. What I'm interested in doing is reformating it into a something more like this: username lastname,... (2 Replies)
Discussion started by: reindeermountai
2 Replies

2. UNIX for Dummies Questions & Answers

Trouble Setting Up Sun Ultra 10 - Displaying Garbage

Hello there, I am new to this forum as well as to the UNIX world. Recently graduated with a degree in Computing and just started learning UNIX & bought 3 Sun Ultra 10 Servers. I was trying to set the Servers up so I can use them; the Servers don't have a VGA card. My laptop, which I would be... (6 Replies)
Discussion started by: frhan2u
6 Replies

3. UNIX for Dummies Questions & Answers

Setting up environment variables

Hi all, This is my first post here. I need to set up a few environment variables with a shell script. Some are hard-coded, but some should come from other commands or as input from the user. How do I do that? For example, I need to export a variable as such: export DISPLAY=127.0.0.1:8.0 ... (2 Replies)
Discussion started by: exchequer598
2 Replies

4. UNIX for Dummies Questions & Answers

setting enviroment variables help

Hello everyone, I am currently trying to program in java in unix platform for the first time, so far it is OK as long as I use class libraries which come with java distribution. Unfortunately when I try to use external libraries I have to use -classpath option which I rather not doing all the... (1 Reply)
Discussion started by: run123
1 Replies

5. UNIX for Dummies Questions & Answers

Setting up variables

Hi all, I have a shell script that sets up the environment for an application running on UNIX - ksh. This script is run using: . ./script_name XX where XX is a parameter. I want to run it from another shell script but when I do it I don't get the envornment variables set up and the prompt... (3 Replies)
Discussion started by: solar_ext
3 Replies

6. UNIX for Advanced & Expert Users

setting some variables

i have a file .NAMEexport MY_NAME=JOE when i do this at the command prompt #. .NAME $echo MY_NAME $JOEi created a script called Run.sh . .NAME At the command prompt i did #sh Run.sh #echo $MY_NAMEit returns nothing. What have i missed out? (7 Replies)
Discussion started by: new2ss
7 Replies

7. UNIX for Dummies Questions & Answers

Setting numbered variables

Normally I would post in the shell scripting area, but this is so basic I thought I'd best put it in the dummy area! I want to set a series of numbered variables. I have a loop which increments a variable called $i with each loop. I want to name variables with this number e.g. var1, var2, var3... (1 Reply)
Discussion started by: michaeltravisuk
1 Replies

8. AIX

Setting Variables not working

Hi all, I am trying to set up some variables in a shell script. The variables contain values of various paths needed to run a java module. The problem is the variables dont seem to be setting at all. here is what i am trying to do : JAR_HOME=/home/was5/bdcms/scheduledjobs/lib export... (1 Reply)
Discussion started by: rpandey
1 Replies

9. UNIX for Dummies Questions & Answers

setting environment variables ???

Hello, I want to set some environment variables with this script: ip=$@ echo Remote Computer: $ip PERLDB_OPTS="CallKomodo=$ip:9000 RemotePort=$ip:9010 PrintRet=0" export PERLDB_OPTS PERL5LIB=/opt/komodo export PERL5LIB echo PERLDB_OPTS: $PERLDB_OPTS echo PERL5LIB: $PERL5LIB But it... (5 Replies)
Discussion started by: Gargamel
5 Replies
Login or Register to Ask a Question