1846625 Members
1878 Online
110256 Solutions
New Discussion

Re: Help with script

 
Junior C.
Frequent Advisor

Help with script

Why am I getting this error when I run this script. script and output error attach

Thanks,
Junior
6 REPLIES 6
Rick Garland
Honored Contributor

Re: Help with script

Put a backslash in front of the *. The shell is trying to interpret
Andreas Voss
Honored Contributor

Re: Help with script

Hi,

could it be that whithin your subirs there are files that begin with -* ?
Check this with a find command.
If so change your ll command to:
ll ./$FILE
This will prevent interpreting the filename as an option for ll.

Regards

Andrew
Alan Riggs
Honored Contributor

Re: Help with script

Might I suggest replacing the entire structure with:

ll -d $RETAILRE/*/* $RETAILRE/*/data.*/* | grep -v "^d" >> $LOGFILE

Re: Help with script

What is it you are trying to do? Perhaps that would help to figure out the best way to get this script to work.
Douglas Nakamoto
Occasional Advisor

Re: Help with script

I would think that the problem is with the syntax of your 'for' statement.

The following logic (utilizing your structure, excerpted from your script - it will have to be inserted, replacing the old logic, to work properly) will do what I think you want:

cd $RETAILRE
for DIR in `ll | grep ^d | awk '{print $9}'`
do
echo $DIR >> $LOGFILE
cd $DIR
for FILE in `ls $DATA`
do
if [[ -f $FILE ]]
then
ll $FILE >> $LOGFILE
fi
done
cd $RETAILRE
done
Jeremy Dean_3
Occasional Advisor

Re: Help with script

Alan and Douglas are on to a winner.

for file in *

will work fine when there are files to match, however when there are none it will return "*" as file once.
This could have been explicitly tested in the original coding loop as an exception case.
Alternatively Alan and Douglas's suggestions are (better) alternatives.

for file in $DATA/*; do
if [ "$file" = "$DATA/*" ]; then
break
fi
...
done

Note that the shell expands $DATA, but not * within the quotes!