Find the answer to your Linux question:
Results 1 to 3 of 3
Hello all. This will be my first post. I need some help with this simple --if statement. I'm writing a program that needs a test statement to test if the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    9

    Test statement in bash


    Hello all. This will be my first post. I need some help with this simple --if statement.
    I'm writing a program that needs a test statement to test if the user selected file is the same as the program being executed. And if it is not, remove it. The name of the program is job06.

    This gives an error...

    if [ "$file" ! -e "job06" ] # line 25
    then
    echo "$file" " has been removed."
    rm "$file"
    fi

    The error is...
    ./job06: line 25: [: too many arguments

  2. #2
    Linux Newbie
    Join Date
    Nov 2012
    Posts
    232
    hi,

    -e stands for file (file or directory) exists.
    lexical equality is simple = (equal sign)

    see:
    Code:
    help test

  3. #3
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    This does not have "test" statement but does the same thing.
    Code:
    if [ $(whoami) != "job06" ]
     then
      echo "job06 must be run by job06, aborting"
     exit 0
    fi

  4. $spacer_open
    $spacer_close

Posting Permissions

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