-   Linux - General (
-   -   insert output of sed into a variable (

hwouters 10-23-2004 02:01 PM

insert output of sed into a variable

This is a shell-related question.

I would like to insert the ip address of the current x-server into a variable. If the Xdmcp-server and x-server are not the same computer, it looks like $DISPLAY gives <ip-adress>:<display-id> . for example:

Is it possible to remove the ':0.0' from $DISPLAY (probably with sed) and insert it into a new variable, like $DISPLAYHOST?

I allready searched the web for it, but I can't find any solution.

(I would like to run programs on the x-server while having a display of a different computer)

Thanks in advance

Sinope 10-23-2004 03:17 PM

You can convert the output of any shell command or pipeline to a string by using backquotes (`).

For example, say you wanted to use some l33t encryption on some data, then send it to a variable for later use.


$ export SECRETDATA=`echo data | rot13`

I'm not exactly clear on why you want to do this particular thingy, but whatever, I'll tell you how you could do it. Use cut, not sed.


$ export $DISPLAYHOST=`echo $DISPLAY | cut -f1 -d:`
This sets $DISPLAYHOST to the first colon-delimited field of $DISPLAY.

hwouters 10-23-2004 04:11 PM

That worked .

THank you very much!

Greetings Hendrik

jschiwal 11-06-2004 07:54 PM

There are several way to do many things. Such a simple variable substitution could be done in bash.

If you wanted the DISPLAY#.SCREEN part:

All times are GMT -5. The time now is 11:02 AM.