Too simple a problem to see sh script

Too simple a problem to see sh script

Post by bill » Sat, 11 Mar 2006 04:41:10



if [ $# < 3 ] ; then   <<<<<< line #12
  printf "Usage : $0 -l log_file -p project -b BB -t topic command\n";
  exit 1;
fi

The result:
exec_log[12]: 3: Cannot find or open the file.

 
 
 

Too simple a problem to see sh script

Post by Chris F.A. Johnso » Sat, 11 Mar 2006 04:50:45



> if [ $# < 3 ] ; then   <<<<<< line #12
>   printf "Usage : $0 -l log_file -p project -b BB -t topic command\n";
>   exit 1;
> fi

> The result:
> exec_log[12]: 3: Cannot find or open the file.

    The 'less than' sign is the shell's redirection operator. To test
    numbers, use integer comparison operators, e.g.:

if [ $# -lt 3 ]; then

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence

 
 
 

Too simple a problem to see sh script

Post by Greg Andre » Sat, 11 Mar 2006 04:55:13



>if [ $# < 3 ] ; then   <<<<<< line #12
>  printf "Usage : $0 -l log_file -p project -b BB -t topic command\n";
>  exit 1;
>fi

>The result:
>exec_log[12]: 3: Cannot find or open the file.

Your shell doesn't use the '<' character to mean "less than" in the test clause (between '[' and ']').  You probably need to use '-lt' instead.

  -Greg
--

     I have a map of the United States that's actual size.
                                -- Steven Wright

 
 
 

Too simple a problem to see sh script

Post by Stephane CHAZELA » Sat, 11 Mar 2006 04:54:40


2006-03-9, 11:41(-08), billy:
Quote:> if [ $# < 3 ] ; then   <<<<<< line #12
>   printf "Usage : $0 -l log_file -p project -b BB -t topic command\n";
>   exit 1;
> fi

> The result:
> exec_log[12]: 3: Cannot find or open the file.

[...]

< is a redirection operator.

[ $# < 3 ]

starts the "[" command with three arguments: "[", "<n>" and "]"
(where <n> is the content of $#) with it's input redirecting
from the file called "3" in the current directory.

ITYM [ "$#" -lt 3 ]

It's printf '...%s...' "$0"
 not printf "...$0..."

the first argument is a format, not an ordinary string.

--
Stphane

 
 
 

1. Execute a sh script under perl and sh: sh script; perl script?

I can execute the following perl scripts under either shell or Perl
====

        if 0;
[perl scripts ...]
====
i.e.
sh script
perl script

How do I execute a sh script under either shell or Perl
simililar to what shown above?

Thanks.
--
Michael Wang

http://www.mindspring.com/~mwang    

2. Voice Processing Driver Compatibility

3. Simple sh script, simple error?

4. Moo-Tif mwm is sluggish

5. simple shell script in sh

6. how to use color wiht ls?

7. a simple /bin/sh script question

8. Memeory Limit on Solaris

9. ksh script --> sh script problems

10. ASCII 128-255 in sh script: sh strips bit 7!!!

11. make sh-script compatible between SUN-sh and bash

12. script or command to find all scripts (ksh, sh, perl, etc) in a workspace

13. how to handle usig csh scripts from within bash/sh scripts?