LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2012, 01:47 AM   #1
priyankabade
LQ Newbie
 
Registered: May 2012
Posts: 5
Blog Entries: 1

Rep: Reputation: Disabled
not able to understand whats going wrong


when i am running scripts it is giving error
./dist_auar_pb.sh: line 156: [: /psoft/batch/fsdev/outbound/auar/atl/archive/AUARCPPSF05.120504: binary operator expected

for code
if [ -f $ARC_DIR/${EXTRACT}* ]
then
find $ARC_DIR/${EXTRACT}* -mtime +45 -exec rm {} \;
fi

but clone copy of this script working fine for same coding
y this??
plz tell me solution what should i do with this script why only this script giving error and not clone scripts
 
Old 05-11-2012, 02:27 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
presumably the *'s are causing multiple file names to be returned. You can't ask if multiple files exist, nor can you find them. when the script works, there is probably only 0 or 1 file that exists.

Your code doesn't really make sense, you seem to want to say "if there are any files matching this pattern, then go find them and delete them". Why bother checking first? Just delete all the ones that are found. If none are found, none are deleted, so you get the same result, but in much less code.
 
Old 05-11-2012, 02:42 AM   #3
priyankabade
LQ Newbie
 
Registered: May 2012
Posts: 5

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Question

@chris
Actually folder contain many other files..
So i am dealing with only start A....*

but the question is it is working fine in other places and why giving problem to this only..
 
Old 05-11-2012, 02:53 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
as I said, I expect there aren't multiple files in those other locations.

"binary operator expected" means "I've been given more strings to process that the operator expects"

if you script something like "if [ -f file1 file2 file3 file4 ]" then what would you expect to happen? what would that mean??

Last edited by acid_kewpie; 05-11-2012 at 02:55 AM.
 
Old 05-11-2012, 03:44 AM   #5
priyankabade
LQ Newbie
 
Registered: May 2012
Posts: 5

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Question

@chris
yes that true..
i think ir wrks bz that tim having one file in folder and i run script..
and about this script when i run it that time more than one files were there..
thats y it failed...

so do you know how i should check for multiple file??
should i use for??
 
Old 05-11-2012, 03:46 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I've already given you my suggestion. Don't check. just do it. How do you benefit from checking?

please try to write full words... y? bz?
 
Old 05-11-2012, 10:00 AM   #7
uhelp
Member
 
Registered: Nov 2011
Location: Germany, Bavaria, Nueremberg area
Distribution: openSUSE, Debian, LFS
Posts: 205

Rep: Reputation: 43
Code:
for this in path/to/A*
 
Old 05-11-2012, 12:01 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.


In addition to the above comments, the syntax of the find command is wrong.

You start by giving find one or more starting directories, not files, and various criteria for matching the contents of those directories. Finally you supply an action for find to take when it matches something (-print by default).

One of the actions available in gnu find is "-delete", BTW.

So you really want something more like this:

Code:
find "$ARC_DIR" -type f -name "<*globpattern*>" -mtime +45 -delete
Since I don't know exactly what your "$EXTRACT" variable contains, I'm leaving it out of the above for the time being. You'll have to figure out how to apply it correctly yourself. Hint: you can give it multiple entries like "-name" at once.

Here are a couple of good links about using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html


Finally, QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
 
  


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
[SOLVED] Whats wrong with Conky? linus72 Slackware 2 09-01-2010 08:01 AM
What is this, whats wrong w/ me? colinstu General 11 12-19-2006 06:50 AM
Whats wrong with python? M$ISBS Programming 15 12-17-2006 12:05 PM
Whats wrong with my XF86Config here: Scruff Linux - General 4 09-17-2003 01:06 AM
Whats wrong with this? OlRoy Programming 2 05-28-2003 01:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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