user14342519
user14342519

Reputation: 25

What is the command to show if vi is running or not

Write a single line ‘if-then-else’ command that prints 1 if vi is running and 0 if it does not.

I wrote:

if [ $.vi -eq 1 ]; then echo "1"; else echo "0"; fi

I don't think that is right. How would I write the command that would print 1 if vi is running?

Upvotes: 0

Views: 529

Answers (2)

Ali Turcan
Ali Turcan

Reputation: 1

You can also try ps -C vi and all the other if statements and redirection would be the same.

Upvotes: 0

wasif
wasif

Reputation: 15518

Thats a bad way, Try like this to check if process (vi) is running

if pgrep -x "vi" > /dev/null
then
    echo "1"
else
    echo "0"
fi

Upvotes: 1

Related Questions