You are not logged in.

#1 2009-09-02 10:27:51

alvin_rxg
Member
From: China / Germany
Registered: 2009-08-18
Posts: 24

[SOLVED] "pgrep" or "if" command dosen't work in ~/.profile

Hello every
maybe after every upgrade, happens always some problem...
I have typed some codes in my .profile to let X start automatic, when i loggin in tty.

### if X dosenot exist, then startx.
if !([[ `pgrep -x X` ]]); then
        startx
fi

It worked fine for a long time.:D
But today it happens in tty:  sad

-bash: Desktop: command not funden

where does command "Desktop" from?

Then i checked where happened it.

### if X dosenot exist, then startx.
echo step 1 ok.
if !([[ `pgrep -x X`]]); then
        echo step 2 ok.
        startx
        echo step 3 ok.
fi

In tty show only step 1 ok. that means "if ... then" may have some problem~ but it worked fine before today.

when i manually startx, and

alvin ~ $ pgrep -x X
4063

it works..

Can someone help me? i'm real noob
Thank you!

Last edited by alvin_rxg (2009-09-02 11:54:54)


real newbie

Offline

#2 2009-09-02 10:45:46

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: [SOLVED] "pgrep" or "if" command dosen't work in ~/.profile

I would have done it the following way although if your code worked previously then I don't know why it no longer does.

 [ -z "$(pgrep -x X)" ] && startx

or

 [ -z "$(pidof X)" ] && startx

Last edited by Xyne (2009-09-02 10:46:26)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#3 2009-09-02 10:52:10

alvin_rxg
Member
From: China / Germany
Registered: 2009-08-18
Posts: 24

Re: [SOLVED] "pgrep" or "if" command dosen't work in ~/.profile

Xyne wrote:

I would have done it the following way although if your code worked previously then I don't know why it no longer does.

 [ -z "$(pgrep -x X)" ] && startx

or

 [ -z "$(pidof X)" ] && startx

thank you for your reply.
and how to type the command?
it shows

-bash: [-z: command not funden

real newbie

Offline

#4 2009-09-02 11:42:23

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] "pgrep" or "if" command dosen't work in ~/.profile

It's probably related to the backticks in `pgrep -x X`. It tries to execute the output/pid. So you need to either test whether the output is empty like Xyne said, or lose the test entirely (pgrep itself returns success/fail) if ! pgrep -x X; then ...

Offline

#5 2009-09-02 11:49:37

Surgat_
Member
Registered: 2007-08-08
Posts: 317

Re: [SOLVED] "pgrep" or "if" command dosen't work in ~/.profile

alvin_rxg wrote:
Xyne wrote:

I would have done it the following way although if your code worked previously then I don't know why it no longer does.

 [ -z "$(pgrep -x X)" ] && startx

or

 [ -z "$(pidof X)" ] && startx

thank you for your reply.
and how to type the command?
it shows

-bash: [-z: command not funden

You must put a blank space between [ and -z, and another one between the inverted commas and the ].

Offline

#6 2009-09-02 11:56:54

alvin_rxg
Member
From: China / Germany
Registered: 2009-08-18
Posts: 24

Re: [SOLVED] "pgrep" or "if" command dosen't work in ~/.profile

than you all.
just forget the space..

think i have to learn some more about bash.


real newbie

Offline

Board footer

Powered by FluxBB