I am trying to write a check in my .cshrc file to see if an X server is running or not. Basically, I only want to run the command that starts the X server if an X server is not already running, because otherwise I get an annoying error message every time I open a new console and it tries to start an X server when one is already running.
My idea is to grep the list of running processes for the existence of the X server process, and if a match is found, then don't run the command to start the X server. Here is what I have:
set myvar = 'ps -ef | grep /usr/X11R6/bin/XWin'
I tried running the command at the console and it correctly returned a single line of text that corresponded to the X server process. The problem is that when I try assigning it to a variable, as I have shown above, the value of myvar only gets the value of ps -ef; it is completely ignoring the pipe and the grep command. How can I get it to recognize the pipe and the grep command, so that myvar ends up with the single line of text corresponding to the X server process (assuming it is running)?
I tried enclosing the command in backticks, but then myvar only captures the UID of the process, not the entire line. In addition, it then apparently tries to execute the UID as a command, because I then get the error message "Administ: Command not found." How can I make this work? I am using csh under cygwin.
My idea is to grep the list of running processes for the existence of the X server process, and if a match is found, then don't run the command to start the X server. Here is what I have:
set myvar = 'ps -ef | grep /usr/X11R6/bin/XWin'
I tried running the command at the console and it correctly returned a single line of text that corresponded to the X server process. The problem is that when I try assigning it to a variable, as I have shown above, the value of myvar only gets the value of ps -ef; it is completely ignoring the pipe and the grep command. How can I get it to recognize the pipe and the grep command, so that myvar ends up with the single line of text corresponding to the X server process (assuming it is running)?
I tried enclosing the command in backticks, but then myvar only captures the UID of the process, not the entire line. In addition, it then apparently tries to execute the UID as a command, because I then get the error message "Administ: Command not found." How can I make this work? I am using csh under cygwin.