Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error message: unary operator expected

Status
Not open for further replies.

viorica

Programmer
Apr 6, 2001
5
US
Unix is totally new to me and this error message I got is totally foreign to me. Can somebody PLEASE look at my code to see why I am getting this unary operator expecter error.
Thank you!!
#!/bin/sh
input = 0
clear
while [ $input != 6 ]
do
echo " Menu Choice"
echo " 1) List date, and users who are currently logging"
echo " 2) Print the current working directory"
echo " 3) List all files in the current working directory"
echo " 4) Check the first argument to the script is"
echo " a file with read permission"
echo " 5) Prompt the user for the name of a file"
echo " create a backup copy of the file by appending"
echo " the prcess ID to the filename entered"
echo " 6) Exit"
echo -n "Enter your choice"
read input
case "$input" in
1) clear
echo "Action 1 taken"
echo -n "The current date is"
date
echo "The current user on the system"
who
sleep 5
;;

2) clear
echo "Action 2 taken"
echo -n "The current working directory is:"
pwd
echo ""
echo "------------Hit enter key to continue-----"
read VAR
sleep 5

;;

3) clear
echo "Action 3 taken"
echo "The file"
ls -al
echo ""
echo "------------Hit enter key to continue-----"
read VAR
sleep 5
;;

4) clear
echo "Action 4 taken"
echo -n "Enter your file name: "
read filename
if [ -r $1 filename ]
then
more $1 filename
else
echo "Error $1 filename does not have the read permission"
fi
echo ""
echo "------------Hit enter key to continue-----"
read VAR
sleep 5
;;

5) clear
echo "Action 5 taken"
echo -n "Enter your file name: "
read filename
if cp $filename $filename.$$
then
echo "Your copied file is $filename.$$"
else
echo " **\n** Cannot copy the request file\n**"
fi
echo "------------Hit enter key to continue-----"
read VAR
sleep 5
;;

6) Exit
echo "------------Hit enter key to continue-----"
read VAR
sleep 5
;;

*) clear
echo "Please enter 1 to 6 only"
echo "------------Hit enter key to continue-----"
read VAR
sleep 5
;;

esac
done
 
which line gives you the error?

(use 'set -x' at the top of your script) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Ok, this is what i got when I added set -x to my code
+ input = 0
menu1: input: command not found
+ clear
+ [ != 6 ]
menu1: [: !=: unary operator expected
 
I think it's getting messed up with on the 1st line where you make the assignment to input. Try removing the spaces that surroud the = sign:

Change:

input = 0

to:

input=0

The Bourne shell is touchy about these things.

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top