Shell script frustration
Garance A Drosehn
gad at FreeBSD.org
Thu Jul 28 16:40:34 GMT 2005
At 10:10 AM +0100 7/28/05, martin at orbweavers.co.uk wrote:
>Garance wrote:
> > What I do in this cases is create a script called "list_args.sh":
>>
>> #!/bin/sh
>> printf "\nlist_args.sh at `date +%H:%M:%S` with \$# = $#\n"
>> # Process all parameters.
>> N=0
>> while test $# != 0 ; do
>> N=$(($N+1))
>> printf " \$$N = [%3d] '$1'\n" ${#1}
>> shift
>> done
>>
>> Then in your script, replace the ldapdelete command with
>> list_args.sh. That way you'll see *exactly* what ldapdelete
>> is seeing for parameters, and that might help.
>
>I tried that one, with an echo $* - though I assume the printf
>prints it out 'more precise'?
Well, I also have versions that use an echo instead of printf.
The printf just makes it easier to have a "pretty" output.
The problem with using a plain 'echo *' is that there are
several different inputs which will produce the same output.
Compare:
echo a b
and echo "a b"
or echo "a b"
and echo "a b "
The outputs from `echo' will look the same, but the arguments to
the program are very different. That's why my script lists out
the exact arguments, with their lengths. I did that because
sometimes those details matter. I have solved problems similar
to the one which is frustrating you by using this kind of script.
--
Garance Alistair Drosehn = gad at gilead.netel.rpi.edu
Senior Systems Programmer or gad at FreeBSD.org
Rensselaer Polytechnic Institute; Troy, NY; USA
More information about the freebsd-questions
mailing list