Operating System - HP-UX
1830213 Members
1408 Online
109999 Solutions
New Discussion

need a easy script for display seting.

 
SOLVED
Go to solution
jayachandran.g
Regular Advisor

need a easy script for display seting.

Hi All


1) All my freinds are using 3 commands

#DISPLAY=ip:0.0;export DISPLAY;echo $DISPLAY)

to set display i want to make it in one script.

So i have writen a script for it as follows
**********************************************
#/sbin/sh
echo "type your local pc ip address below"
read ip
DISPLAY=$ip:0.0
export DISPLAY
echo DISPLAY
**********************************************
it shows correctly till echo
but as if it is running in a child shell (i hope i'm correct) the setting is getting disappeared at the end when it return back to its parent shell
is thr any way to make it set for its parent shell also.

tell me is thr any way to do it.
thank you
10 REPLIES 10
Slawomir Gora
Honored Contributor

Re: need a easy script for display seting.

Hi,

you need to execute you script by:

a) in sh,ksh shell:
. ./your_script_name

or

. /full_path/your_script_name

b) in csh, tcsh
source ./you_script_name

Ps,

replace echo DISPLAY to echo $DISPLAY
Patrick Wallek
Honored Contributor

Re: need a easy script for display seting.

You don't just run the script, you have to source it.

$ . /scriptname

Or my easy way to do it:

$ export DISPLAY=host:0.0

There you go. 1 statement.
Gopi Sekar
Honored Contributor

Re: need a easy script for display seting.


you have to execute the script in current shell, generally it is executed in the sub shell.

execute the commands with in { } and source it using ./script
Never Never Never Giveup
jayachandran.g
Regular Advisor

Re: need a easy script for display seting.

hi all

************
Slawomir

see i have given that script 755 as permision and i have copied it to /usr/bin

then only i have executed it..

i tried in ./fullpath/script but the too once the script ends the setting is disappeared

and it is acutally echo $DISPLAY only i have mis typed in this
********************

Hi Patrick

I have tried yours too..
but no working.. same

export DISPLAY ( i don't want normal users to know unix.. and i want them to use my the simpliest way)

************************************

Hi gopi

i do not how to use {} in scriopts i have tried this

echo "type your local pc ip address below"
read ip
{DISPLAY=$ip:0.0
export DISPLAY}
echo $DISPLAY

but when i xecute it is telling that thr is error in my script
LD[3]:DISPLAY=172.14.14.2:0.0}: not found
LD[4]:DISPLAY} is not an identifier
****************************************8


any other way to do the same
thank you
Gopi Sekar
Honored Contributor

Re: need a easy script for display seting.



my mistake, I believe i dint read the question clearly. modify the script like this

#/sbin/sh
echo "type your local pc ip address below"
read ip
export DISPLAY=$ip:0.0
echo DISPLAY

and then call the script like this

. /path/to/script

The dot before the script name is very important because it tells the bash not to spawn a subshell rather to use the current shell itself

Hope this helps,
Gopi

Never Never Never Giveup
DCE
Honored Contributor

Re: need a easy script for display seting.

To do it in one line:

export DISPLAY=ip:0.0


The last line in your script should read
echo $DISPLAY

whenever you reference a variable after it has been set, you must use the form $VARIABLE_NAME

Dave
Gopi Sekar
Honored Contributor

Re: need a easy script for display seting.


i forgot to tell you that there should be a space between . and the path to the script.

eg: . /path/to/script

no points for this pls...
Never Never Never Giveup
Rick Garland
Honored Contributor
Solution

Re: need a easy script for display seting.

I use the 'who -um' command when I connect to another system.

My profile on the remote system will execute who -um and I run through awk to get last field

who -um | awk '{print $NF}'

So when I connect the profile has
export DISPLAY=`who -um | awk '{print $NF}'`:0

My DISPLAY is always exported

jayachandran.g
Regular Advisor

Re: need a easy script for display seting.

Sorry Slawomir and Partick really sorry

i have not seen that space between the dot...

now i got cleared both of you r very great...

Gopi your answer is correct but what Slawomir and Partick said is explaied below that is a excellent answer for one and all

instead of using ./fullpath/script (which i have tried and got failed) i must be using
. ./script (rember two dots inbetween a space " . ./" if the script is in your working directory)

is the solution..

there is still a more to tell if the script is not in the present directory then insted of using ". ./" we must use ". /full path/script" ("dot space full path")

Thanks A lot
good luck for all
jayachandran.g
Regular Advisor

Re: need a easy script for display seting.

Hi Rick

all my problem is sloved you gave a wonderful answer..

no comments

try this bye bye
banner "Rick is great"