|
Home > Archive > Unix Shell > April 2005 > testing for directory fails
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
testing for directory fails
|
|
| Mr_Bill 2005-04-20, 5:52 pm |
| The commented out code fails with:
"./my-script: line 45: [: test/html/: binary operator expected"
Everything else works as expected. $author is valid.
Any clues for the clueless?
Thanks.
if [ $? = 0 ];then
author=$(grep "lg=us" $directory/tmp.html | cut -d '>' -f2 | cut -d '<' -f1 | cut -d ' ' -f4)
subject=$(grep "><big><b>" $directory/tmp.html | cut -d '>' -f6 | cut -d '<' -f1)
if [ ! -z "$author" ];
then
echo "AUTHOR: "$author""
fi
if [ ! -d $directory/html ];
then
mkdir -p $directory/html
fi
# if [ ! -d $directory/html/$author ];
# then
# mkdir -p $directory/html/$author
# fi
echo $author > $directory/author_test$start_message.html
echo "subject: $subject"
echo "$ybase $page" > $directory/$start_message.html
else
deleted_posts=$( expr $deleted_posts + 1 )
#echo -e "\033[40;32m"
echo "Message $start_message unavailable"
echo "$(date) message $start_message was unavailable<br>" >> $directory/deleted_posts.txt
fi
| |
| Barry Margolin 2005-04-20, 8:48 pm |
| In article <pan.2005.04.20.22.42.52.703763@nomail.org>,
Mr_Bill <nothanks@nomail.org> wrote:
> The commented out code fails with:
> "./my-script: line 45: [: test/html/: binary operator expected"
Does $author have any spaces in it? If so, you need to quote it:
if [ ! -d "$directory/html/$author" ]
>
> Everything else works as expected. $author is valid.
>
> Any clues for the clueless?
>
> Thanks.
>
> if [ $? = 0 ];then
>
> author=$(grep "lg=us" $directory/tmp.html | cut -d '>' -f2 | cut -d '<' -f1 |
> cut -d ' ' -f4)
> subject=$(grep "><big><b>" $directory/tmp.html | cut -d '>' -f6 | cut -d '<'
> -f1)
>
> if [ ! -z "$author" ];
> then
> echo "AUTHOR: "$author""
> fi
>
> if [ ! -d $directory/html ];
> then
> mkdir -p $directory/html
> fi
>
> # if [ ! -d $directory/html/$author ];
> # then
> # mkdir -p $directory/html/$author
> # fi
>
> echo $author > $directory/author_test$start_message.html
>
> echo "subject: $subject"
>
>
> echo "$ybase $page" > $directory/$start_message.html
>
> else
>
> deleted_posts=$( expr $deleted_posts + 1 )
> #echo -e "\033[40;32m"
> echo "Message $start_message unavailable"
> echo "$(date) message $start_message was unavailable<br>" >>
> $directory/deleted_posts.txt
> fi
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Mr_Bill 2005-04-21, 2:54 am |
| On Wed, 20 Apr 2005 20:39:43 -0400, Barry Margolin solved my error
and then. . . . .
# if [ ! -d $directory/html/$author ];
# then
# mkdir -p $directory/html/$author
# fi
Thanks , Barry! But now, the mkdir line does work as expected.
(It didn't at all before). If I quote it:
mkdir -p "$directory/html/$author" it creates the directory
but there is no name listed just "/". If I open that, I can see its
name in the URL window is test/html/%0A%0Awilliammark.
If I don't quote it, the directories are created properly, but in
the same directory I execute the script from (one above "test").
Do you have any further advice?
Thanks again,
Mr_Bill
| |
| Mr_Bill 2005-04-21, 5:59 pm |
| On Thu, 21 Apr 2005 08:12:02 +0000, Mr_Bill wrote:
> If I open that, I can see its
> name in the URL window is test/html/%0A%0Awilliammark.
Another thing... If I run ls-l in the html directory I
would get ??williammark listed as a directory but I can't
cd into it.
When the mkdir -p "$directory/html/$author" line is not
quoted, the directory is normal in every way, just not
located where it needs to be.
T'anks
Mr_Bill
| |
| Michael Tosch 2005-04-21, 5:59 pm |
| Mr_Bill wrote:
> On Thu, 21 Apr 2005 08:12:02 +0000, Mr_Bill wrote:
>
>
>
>
> Another thing... If I run ls-l in the html directory I
> would get ??williammark listed as a directory but I can't
> cd into it.
>
> When the mkdir -p "$directory/html/$author" line is not
> quoted, the directory is normal in every way, just not
> located where it needs to be.
>
> T'anks
>
> Mr_Bill
It is a bad idea to use a directory/file name with special characters.
Better use a harmless file name, and write the name into it (or an auxiliary file)!
E.g. filter the harmful characters by
harmless=$(echo "$author" | tr -cd '[a-zA-Z]')
mkdir "$directory/$harmless"
You can of course still access a ??directory by using wild cards:
cd *williammark* should work.
rm -r -- *williammark* should delete it.
--
Michael Tosch @ hp : com
| |
| Mr_Bill 2005-04-21, 8:48 pm |
| On Thu, 21 Apr 2005 19:30:48 +0200, Michael Tosch wrote:
> harmless=$(echo "$author" | tr -cd '[a-zA-Z]')
> mkdir "$directory/$harmless"
Thankin' You!
I have to preserve underscores but your idea lead me to:
new_author=$(echo "$author" | tr -d [:cntrl:])
Thanks again,
Mr_Bill
| |
| Michael Tosch 2005-04-24, 2:50 am |
| Mr_Bill wrote:
> On Thu, 21 Apr 2005 08:12:02 +0000, Mr_Bill wrote:
>
>
>
>
> Another thing... If I run ls-l in the html directory I
> would get ??williammark listed as a directory but I can't
> cd into it.
>
> When the mkdir -p "$directory/html/$author" line is not
> quoted, the directory is normal in every way, just not
> located where it needs to be.
>
> T'anks
>
> Mr_Bill
It is a bad idea to use a directory/file name with special characters.
Better use a harmless file name, and write the name into it (or an auxiliary file)!
E.g. filter the harmful characters by
harmless=$(echo "$author" | tr -cd '[a-zA-Z]')
mkdir "$directory/$harmless"
You can of course still access a ??directory by using wild cards:
cd *williammark* should work.
rm -r -- *williammark* should delete it.
--
Michael Tosch @ hp : com
| |
| Michael Tosch 2005-04-27, 5:58 pm |
| Mr_Bill wrote:
> On Thu, 21 Apr 2005 08:12:02 +0000, Mr_Bill wrote:
>
>
>
>
> Another thing... If I run ls-l in the html directory I
> would get ??williammark listed as a directory but I can't
> cd into it.
>
> When the mkdir -p "$directory/html/$author" line is not
> quoted, the directory is normal in every way, just not
> located where it needs to be.
>
> T'anks
>
> Mr_Bill
It is a bad idea to use a directory/file name with special characters.
Better use a harmless file name, and write the name into it (or an auxiliary file)!
E.g. filter the harmful characters by
harmless=$(echo "$author" | tr -cd '[a-zA-Z]')
mkdir "$directory/$harmless"
You can of course still access a ??directory by using wild cards:
cd *williammark* should work.
rm -r -- *williammark* should delete it.
--
Michael Tosch @ hp : com
| |
| Mr_Bill 2005-04-27, 5:58 pm |
| On Thu, 21 Apr 2005 19:30:48 +0200, Michael Tosch wrote:
> harmless=$(echo "$author" | tr -cd '[a-zA-Z]')
> mkdir "$directory/$harmless"
Thankin' You!
I have to preserve underscores but your idea lead me to:
new_author=$(echo "$author" | tr -d [:cntrl:])
Thanks again,
Mr_Bill
|
|
|
|
|