scripts and reading from command line

scripts and reading from command line

Post by Ahkmed Jone » Fri, 23 Nov 2001 23:14:18



Hi,

This is probably a very easy question. When writing a bash script, how do
you get the script to read parameters from the shell command line?

e.g.

$  <executable script> -t

How would I get the script to read the "-t" and know that modification was
specified?

 
 
 

scripts and reading from command line

Post by j.. » Fri, 23 Nov 2001 23:54:13



> This is probably a very easy question. When writing a bash script,
> how do you get the script to read parameters from the shell command
> line?

> e.g.

> $  <executable script> -t

> How would I get the script to read the "-t" and know that
> modification was specified?

Look at the man page for getopt. The ones I've seen have a sample
program after the description. Some shells (bash, ksh) have a builtin
called getopts, which is described in the man page for the shell.

 
 
 

1. Question about reading the output of a command line by line

All,
I need to get certain elements of the output of
`pkginfo -l` on a Solaris system.

Using Korn Shell, is there any syntax similar to the following
Perl snippet:

open( PKGINFO, "/bin/pkginfo -l |" ); # creates a filehandle

  while( chop( $line = <PKGINFO> ) ) {
    if ( index( $line, "   PKGINST:  " ) == 0 ) {
      $pkg = substr( $line, 13 );
    } elsif( index( $line, "  CATEGORY:  " ) == 0 ) {
      $cat = substr( $line, 13 );
    } elsif( index( $line, "   VERSION:  " ) == 0 ) {
      $ver = substr( $line, 13 );
      printf( "%-13s %-22s %s\n", $pkg, $cat, $ver );
    }
  }

For whatever reason, I need to use shell instead of Perl, and
converting sequences like the above have proven difficult at
best.  

I have considered redirecting stdout to a file, then using
sed or awk to get the bits of info I need, but that seems
shabby.  Am I missing something?  

TIA for any insight

2. >> Diamond Stealth 32 VLB & XFree86 3.1 HELP !!!<<

3. read a file line by line in csh script

4. rivafb

5. Reading a script file line by line.

6. First the forgery, then the expected threats ...CAN ANYBODY KILL THIS OFF TOPIC HARANGUE??

7. How do I read a file line by line in a csh script?

8. Redt Hat Package Manager queries

9. # How to read a textfile line by line using csh shell script ?

10. ksh script --reading file line by line?

11. HELP -- execute some scripts from the command line as a command??????

12. How to read text line-by-line in shell script?

13. Can a script output a command to the Command line as though typed