Find the answer to your Linux question:
Results 1 to 5 of 5
The purpose of this is, if Hw1 is open then echo an message, otherwise open hw2. My code is If [ps -ef | grep hw1] then true echo "hw1 is ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    7

    why isn't this line working for me, bash help

    The purpose of this is, if Hw1 is open then echo an message, otherwise open hw2.
    My code is

    If [ps -ef | grep hw1]
    then true
    echo "hw1 is open"
    else
    cat hw2
    fi

  2. #2
    Linux Engineer
    Join Date
    Nov 2004
    Location
    Ft. Polk, LA
    Posts
    796

  3. #3
    Linux Newbie raghaven.kumar's Avatar
    Join Date
    Mar 2008
    Location
    Bangalore, India
    Posts
    209
    because when you give a grep command it is run as a process.
    so your grep hw1 is also shown in the output.

    Try somethin like
    ps -ef | grep hw1 | grep -v grep
    means that output statements that dont have grep.

  4. #4
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Quote Originally Posted by raghaven.kumar View Post
    because when you give a grep command it is run as a process.
    so your grep hw1 is also shown in the output.

    Try somethin like
    ps -ef | grep hw1 | grep -v grep
    means that output statements that dont have grep.
    one less grep process
    Code:
    ps -ef|awk '/bash/&&!/awk/'
    or
    Code:
    if [ ! -z $(pidof program) ]

  5. #5
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    You need to use some quotes:

    Code:
    If [ `ps -ef | grep hw1` ]
    The quotes are found using shift and the key above tab
    Linux User #453176

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...