LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy
User Name
Password
Puppy This forum is for the discussion of Puppy Linux.

Notices


Reply
  Search this Thread
Old 06-10-2015, 09:31 AM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
-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
 
Old 06-10-2015, 09:33 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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

Last edited by schneidz; 06-10-2015 at 09:47 AM.
 
Old 06-10-2015, 09:49 AM   #3
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
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 ]
 
Old 06-10-2015, 09:53 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Fixit7 View Post
How do I find out what value = ?
Code:
echo value = \"$value\"
 
Old 06-10-2015, 10:03 AM   #5
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Quote:
echo value = "$value"
gives

Quote:
value = ""
 
Old 06-10-2015, 10:11 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^ so since the -eq operator expects one number and nothing ("") is not a number, the if statement exits with an error.
 
Old 06-10-2015, 10:19 AM   #7
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
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"
 
Old 06-10-2015, 10:27 AM   #8
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
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

Last edited by Fixit7; 06-10-2015 at 10:38 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unary operator expected jnojr Linux - General 1 10-18-2012 04:20 PM
-ge: unary operator expected daisychick Linux - Software 8 09-17-2012 12:56 AM
[SOLVED] -gt: unary operator expected hd_pulse Programming 10 05-28-2011 07:57 AM
[SOLVED] unary operator expected hd_pulse Programming 8 05-26-2011 11:01 PM
unary operator expected MONKEYJUDO Linux - Newbie 1 07-13-2008 06:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy

All times are GMT -5. The time now is 02:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration