[: =: unary operator expected error


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [: =: unary operator expected error
# 1  
Old 12-04-2010
[: =: unary operator expected error

Why am I getting this error.... [: =: unary operator expected error
Thanks in advance.
giving me an error on the bolded lines

Code:
#!/bin/sh
# iOS-Ad-Remover
# Marshall Ford @ marshallbford@gmail.com
# This project is hosted @ http://ios-ad-
# remover.sourceforge.net
# Under the GNU GPL open source license


clear
echo
if [ `id -u` != 0 ]; then echo "You need to be root to run this script."; exit 0; # required by reboot command
echo
fi
set -xv
if [ -f "/var/mobile/iOS_Ad_Remover-`date +%d%m%y`.log" ]; then
rm iOS_Ad_Remover-`date +%d%m%y`.log
fi

logname=iOS_Ad_Remover-`date +%d%m%y`.log
echo "iOS-Ad-Remover Log File" >> $logname
datetime=`date +%c_%p`
echo "$datetime" >> $logname
deviceinfo="Device: "`deviceinfo -p`
echo "$deviceinfo" >> $logname

if [ -f "/var/lib/dpkg/info/com.ericasadun.utilities.list" ]; then # Erica Utilities check
:
else
echo "Erica Utilities not installed" >> $logname
echo "Error: You need to install Erica Utilities from Cydia"
sleep 5
exit
fi

if [ -d "/Applications/iFile.app" ]; then # iFile check
:
else
echo "Error: iFile not installed" >> $logname
echo "You need to install iFile from Cydia"
sleep 5
exit
fi

echo "Erica Utilities and iFile installed" >> $logname

if [ -f "/var/mobile/adremover.sh" ]; then
:
else
echo "This script is not called adremover.sh or is not located at /var/mobile/adremover.sh"
echo "Error: Script name or location not correct" >> $logname
fi
date # Start intro
echo
echo "Welcome to iOS-Ad-Remover Beta 1.0
"
sleep 3
echo "This script is similar to Adblock in that it will remove ads from most apps, some websites, and in Cydia.
"
sleep 5
echo "Click RETURN when you want to continue
"
read
echo "You will need to meet the following requirements...
"
read
echo "1. iFile and Erica Utilities installed and updated
"
read
echo "2. This script must be located @ /var/mobile
"
read
echo "3. This script will perform a reboot, you must have an untethered jailbreak or have access to a computer to power back on.
"
sleep 3
echo # end intro

echo "Have you completed the requirements and still want to continue?
"
echo "y/n?
"
read answer
if [ $answer = "y" ]; then
clear
# download host file
echo "Do you have the latest host file downloaded and located in /var/mobile/Media/Downloads?
"
echo "y/n?
"
read hosta
if [ $hosta = "y" ]; then
:
if [ -f "/var/mobile/Media/Downloads/fhosts" ]; then
:
else
echo "The host file does not exist"
echo "Error: The host file did not exist" >> $logname
sleep 3
openURL http://sourceforge.net/projects/ios-ad-remover/files/iOS-Ad-Remover/
exit
fi
fi
if [ $hosta = "n" ]; then
echo "User sent to download host file" >> $logname
openURL http://sourceforge.net/projects/ios-ad-remover/files/iOS-Ad-Remover/
exit
fi

echo # backup process
sleep 1
echo
echo "Backing-up"
sleep 3 
cd ..
cd ..
cd var/mobile/Media/Downloads
if [ -d "/var/mobile/Media/Downloads/Backup" ]; then
:
else
mkdir Backup
fi

cd ..
cd ..
cd ..
cd ..
cd etc
cp fhosts /var/mobile/Media/Downloads/Backup
cd /var/mobile/Media/Downloads/Backup
cp fhosts $datetime-backup-fhosts # rename process
rm fhosts # rename process
echo
echo "Done"
echo
echo "Old host file backed-up" >> $logname # backup done
sleep 1
echo "Changing the host file..."
sleep 3
cd ..
cd ..
cd ..
cd ..
cd ..
cd etc
rm fhosts
cd ..
cd /var/mobile/Media/Downloads
cp fhosts /etc
cd ..
cd /var/mobile/Media/Downloads
rm fhosts
echo
echo "You have successfully removed the majority of ads on iOS.
"
echo "You have successfully removed the majority of ads on iOS" >> $logname
sleep 3
echo "If you find an app that does not function"
echo "because of the ad-removal please contact me at marshallbford@gmail.com"
read
echo "Reboot performed" >> $logname
reboot # needed to insure host file install
fi

if [ $answer = "n" ]; then

clear
echo "iOS-Ad-Remover was stopped by the user" >> $logname
echo "iOS-Ad-Remover was stopped by the user."
sleep 3
echo
echo "Good Bye"
sleep 3
fi


Last edited by mbf123; 12-11-2010 at 07:58 PM..
# 2  
Old 12-04-2010
Try to quote all occurrences of the following variable de-references:

Code:
 [ $answer = "y" ]

should be:

Code:
[ "$answer" = "y" ]

and:

Code:
[ $hosta = "y" ]

should be:

Code:
[ "$hosta" = "y" ]


Last edited by radoulov; 12-05-2010 at 05:14 AM..
# 3  
Old 12-05-2010
Does not work, it just ignores the if then statements when i add the quotes.
# 4  
Old 12-05-2010
Try by changing all occurences to
Code:
[[ $answer = "y" ]]

instead of

Code:
 
[ $answer = "y" ]

# 5  
Old 12-05-2010
Nope this does not work, everything was working fine until I came across this error, basically the script ends at the line
Code:
echo "Have you completed the requirements
and still want to continue?"
echo
echo "y/n?"

It just stops.
I am running this on my iphone? Would that make a difference?
Thanks for all the feedback.
# 6  
Old 12-06-2010
Ignoring the iPhone factor and viewing this just as a Shell problem.

You have places where an "echo" has become two lines when it should be one line.

Code:
echo "You will need to meet
the following requirements..."

echo "2. This script must be located
@ /var/mobile"

echo "Have you completed the requirements
and still want to continue?"


Each of the three examples above needs the linefeed removed from the end of the first line.

Check carefully against the original code in case you have more paste errors.
# 7  
Old 12-06-2010
thanks for the pointer but I would like to fix the bug before I focus on non code breaking things.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unary operator expected

In all my Googling, this usually happens when someone is comparing a variable, and that variable is unset. That doesn't appear to be the case for me... #!/bin/bash -x while read line do f=$(echo $line | tr -s ' ' | cut -d' ' -f 3) echo $f if then echo "This... (2 Replies)
Discussion started by: jnojr
2 Replies

2. Shell Programming and Scripting

unary operator expected, if condition test error.

Hi All, I'm assigning a numeric value to variable count=2, well its being assigned by code above the if condition. I want to test for 2 conditions , when $count = 0 or $count <=2 and do something when the condition matches. here is my code, but i run into the infamous : if ] then ... (2 Replies)
Discussion started by: Irishboy24
2 Replies

3. UNIX for Dummies Questions & Answers

[: -gt: unary operator expected

Hi I have problem with my script. I dont now why but i don't change anything and script stop working. this is my code: #!/bin/sh for i in `ps -A | grep pocron.sh | grep -v grep | awk '{print $2}'` do COUNT=$((COUNT+1)) done ostatnie_wykonanie=`cat porader.log`... (1 Reply)
Discussion started by: fotex
1 Replies

4. UNIX for Dummies Questions & Answers

: unary operator expected

Hiya all, Why do I get a :unary operator expected when I try to put a condition statement in my shell script (sh) like so and how to fix? if ; then echo "say hello" else echo "don't say hello" fi ? It seems if the script receives an argument it works but if I don't put an... (4 Replies)
Discussion started by: cyberfrog
4 Replies

5. Shell Programming and Scripting

unary operator expected

i=0 while Shell script reports an error "unary operator expected" pointing the above line. $i by default is 0 and holds integer value and $buf is also holding integer value. Please can some one let me know what is missing. Thanks. (1 Reply)
Discussion started by: sunrexstar
1 Replies

6. UNIX for Dummies Questions & Answers

Error : -ne: unary operator expected

find . -name "*.*"|xargs grep WT:DBF_WL>> $F Wfexist=`cat $F|grep $i` echo $Wfexist if ; then echo $Wfexist echo "Workflow Exist" else touch $O chmod 777 $O echo $Wfexist echo $WfExist >> $O fi I am getting the error that -ne: unary operator expected in the line with red... (2 Replies)
Discussion started by: ritu.s
2 Replies

7. Shell Programming and Scripting

unary operator expected

Im trying to fix my /etc/weekly that rotates various logs however it does them no matter what filesize they are and i want them to only do it if there file size exceeds 2M or something. So I'm playing with a script to get the filesize using a ls -l command which works and puts the value into a... (3 Replies)
Discussion started by: timgolding
3 Replies

8. UNIX for Dummies Questions & Answers

[: =: unary operator expected

HI, while running a script, I got the below mentioned error. /bin/sh: line10 : supportedMozillaVersion() { case "$*" in *rv:1.*) return 0;; *rv:.*) return 0;; *rv:*) return 1;; Mozilla\ 1.*) return 0;; Mozilla\ .*) return 0;; *) return 1;; esac } supportedFirefoxVersion() { case... (7 Replies)
Discussion started by: bhag281
7 Replies

9. Shell Programming and Scripting

unary operator expected

hi i am trying to compare a value with value 50. but i am getting " I am using if then echo "------------" fi please help thanks in advance Satya (2 Replies)
Discussion started by: Satyak
2 Replies

10. UNIX for Dummies Questions & Answers

unary operator expected error

Hi I am doing a script like if then echo "table name dosent exist" exit fi the problem is if $table_name is null then i am getting the error Please help me Thanks in advance (2 Replies)
Discussion started by: ssuresh1999
2 Replies
Login or Register to Ask a Question