Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:58:03+00:00 2026-06-14T19:58:03+00:00

I want to test if two variables exist, after i used read to create

  • 0

I want to test if two variables exist, after i used “read” to create it. If the user enter just one of two variables i want, it display an error.

There is my code :

while true;
do
  echo "Saisissez deux variables x et y sous la forme [x y]"
  read x y

  if [ !-e $x ] || [ !-e $y ] <<<<<< problem ligne
  then
    echo "Vous devez renseigner deux nombres x et y"
  elif [ $x = "." ]
  then
    exit 0
  else
    calcul $x $y
  fi
done

and there is the error when i just enter an argument :

[: !-e: unary operator expected

Thanks for your help 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:58:04+00:00Added an answer on June 14, 2026 at 7:58 pm

    Change it to:

    if [ -z "$x" ] || [ -z "$y" ]
    

    Explanation

    • [ is actually a shell built-in (try which [ or help [ on your prompt); it’s is a synonym for test.
    • -z is an argument to [. it means “test if the length of the next string is 0; return true if so; return false otherwise.
    • Always wrap the variables you are testing with double quotes!

    Here’s a list of useful options to [ since I think you’d be interested:

    -b file = True if the file exists and is block special file. 
    -c file = True if the file exists and is character special file. 
    -d file = True if the file exists and is a directory. 
    -e file = True if the file exists. 
    -f file = True if the file exists and is a regular file 
    -g file = True if the file exists and the set-group-id bit is set. 
    -k file = True if the files "sticky" bit is set. 
    -L file = True if the file exists and is a symbolic link. 
    -p file = True if the file exists and is a named pipe. 
    -r file = True if the file exists and is readable. 
    -s file = True if the file exists and its size is greater than zero. 
    -s file = True if the file exists and is a socket. 
    -t fd = True if the file descriptor is opened on a terminal. 
    -u file = True if the file exists and its set-user-id bit is set. 
    -w file = True if the file exists and is writable. 
    -x file = True if the file exists and is executable. 
    -O file = True if the file exists and is owned by the effective user id. 
    -G file = True if the file exists and is owned by the effective group id. 
    file1 –nt file2 = True if file1 is newer, by modification date, than file2. 
    file1 ot file2 = True if file1 is older than file2. 
    file1 ef file2 = True if file1 and file2 have the same device and inode numbers. 
    -z string = True if the length of the string is 0. 
    -n string = True if the length of the string is non-zero. 
    string1 = string2 = True if the strings are equal. 
    string1 != string2 = True if the strings are not equal. 
    !expr = True if the expr evaluates to false. 
    expr1 –a expr2 = True if both expr1 and expr2 are true. 
    expr1 –o expr2 = True is either expr1 or expr2 is true.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's suppose I have following two variables: arg1=5 count5=test Now, I want to able
I want to create Many-One Mapping between two tabels, Expense(ID, NAME, CATEGORY) and Category(ID,
I want to test whether two languages have a string in common. Both of
I want regExp to test for two 'Hello'-s and return true but it only
I want to test Add new item activity in my application. When user fills
I want to test for transition from one state to another. I have defined
I am implementing a user theory plug-in. I want to test inconsistency in the
I'm writing a user's GUI and I want to create a method that will
Beginner programmer here. after a bunch of reading about 'variables' which dont exist in
I have a 2 variables with various lengths. I want to create a for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.