LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Puppy (https://www.linuxquestions.org/questions/puppy-71/)
-   -   -eq: unary operator expected (https://www.linuxquestions.org/questions/puppy-71/eq-unary-operator-expected-4175544991/)

Fixit7 06-10-2015 09:31 AM

-eq: unary operator expected
 
Code:

value= [ -e /mnt/sda1/Windows_XP_Partition ]
if [ $value -eq 1 ]
then
  echo "XP Part is present"
else
  echo "I didn't find the XP Part"
fi

I do not understand this error message.

Quote:

# ifelse.sh
/root/Scripts/ifelse.sh: line 8: [: -eq: unary operator expected
I didn't find the XP Part

schneidz 06-10-2015 09:33 AM

what does value equal ?

edit: this worx for me:
Code:

schneidz@xbmc:~/tmp$ cat fixit.ksh
#!/bin/bash

[ -e /mnt/sda1/Windows_XP_Partition ]
if [ $? -eq 0 ]
then
  echo "XP Part is present"
else
  echo "I didn't find the XP Part"
fi
schneidz@xbmc:~/tmp$ ./fixit.ksh
I didn't find the XP Part


Fixit7 06-10-2015 09:49 AM

How do I find out what value = ?

When run in a console, there is no error message
for

Quote:

[ -e /mnt/sda1/Windows_XP_Partition ]

schneidz 06-10-2015 09:53 AM

Quote:

Originally Posted by Fixit7 (Post 5375106)
How do I find out what value = ?

Code:

echo value = \"$value\"

Fixit7 06-10-2015 10:03 AM

Quote:

echo value = "$value"
gives

Quote:

value = ""

schneidz 06-10-2015 10:11 AM

^ so since the -eq operator expects one number and nothing ("") is not a number, the if statement exits with an error.

Fixit7 06-10-2015 10:19 AM

When I run this with sda1 mounted and unmounted, the FILE values are correct.

Yet there is no message that the file was not found. ??

Quote:

FILE=/mnt/sda1/menu.lst

# Check if $FILE exists or not on the Windows partition
if test ! -f "$FILE"
then
echo "Error - $FILE not found."
exit 1
fi
echo value = "$FILE"

Fixit7 06-10-2015 10:27 AM

The -e fixed it. :-)

Quote:

if test ! -e "$FILE"
Quote:

#!/bin/bash
#
# Perform an action based on whether a file exists
# Much help from schneidz
clear
FILE=/mnt/sda1/menu.lst
# Check if File exists or not
if test ! -e "$FILE"
then
echo "Error - $FILE not found."
else
echo "$FILE found."
thunar /mnt/sda1/

fi
I wonder what a regular file is ?

-
Quote:

e FILE
FILE exists
-f FILE
FILE exists and is a regular file


All times are GMT -5. The time now is 07:02 AM.