[fu-t set]
in comp.unix.misc i read:
perhaps you should resolve these deficiencies -- not that there is anythingQuote:>I'm sorry but it's the ONLY way I can write this. I don't know how to
>read standard in in TCL; I don't know how to do complex string
>manipulation in Bash. So I have to write in the languages based on
>what I know.
wrong with using tcl from bash or bash from tcl, but it doesn't appear
necessary in this case.
in terms of shell scripting you don't have much debugging experience, in
particular you don't appear to have used ``set -vx'' to expose the
operations occurring. which would lead to the real problem: you aren't
using enough quoting, which is causing ...
you have a test which expects certain arguments and they are not beingQuote:>Problem arises in fileremoval.sh - it just plain does not work, here
>is the error:
>/home/phillip/scripts/fileremoval.sh: [: ==: unary operator expected
provided. you use bare variable expansion, which does not result in an
argument being created if the variable is unset or empty. let's look at
what that looks like using set -x.
my little test script, which is whittled down to just the problem, is:
#!/usr/bin/bash
set -x
foo=''
[ $foo == 'Y' ]
executing this provides the following output:
+ foo=
+ '[' == Y ']'
./foo.sh: line 4: [: ==: unary operator expected
as you can see there is no argument before the == (which is non-standard
btw), because foo is empty. to ensure that an argument is created you need
to use quotes, i.e.,
#!/usr/bin/bash
set -x
foo=''
[ "$foo" == 'Y' ]
which after expansion becomes:
+ foo=
+ '[' '' == Y ']'
there we see that there is an empty argument being provided.
--
a signature