LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   insert output of sed into a variable (http://www.linuxquestions.org/questions/linux-general-1/insert-output-of-sed-into-a-variable-246398/)

hwouters 10-23-2004 02:01 PM

insert output of sed into a variable
 
Hi,

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: 192.168.0.31:0.0

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.

Code:

$ export SECRETDATA=`echo data | rot13`
$ echo $SECRETDATA
qngn

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.

Code:

$ 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.
export $DISPLAYHOST="${DISPLAY%:*}"

If you wanted the DISPLAY#.SCREEN part:
export $DISPLAYHOST="${DISPLAY#*:}"


All times are GMT -5. The time now is 05:58 PM.