Reputation: 25
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
Reputation: 1
You can also try ps -C vi and all the other if statements and redirection would be the same.
Upvotes: 0
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