Kornshell convdate


 
Thread Tools Search this Thread
Top Forums Programming Kornshell convdate
# 1  
Old 12-30-2003
Question Kornshell convdate

Hello,

I'm currently doing some programming using the Kornshell environment. I have just been on a Unix course where our instructor gave us some coding examples. I am using one of these examples to solve a few problems.

However, the code examples use a function called 'convdate' to convert a date into seconds since 1970. I do not have this function on this version of Unix. I have looked on the internet and found that it is a common function to have.

Please could someone advise me as to where to get a copy of this function from. How to install it on Unix so I (and preferably my other 3 programming colleagues) can see and use it.

Any help will be much appreciated.

Thanks.
# 2  
Old 12-30-2003
nezster,

At the bottom of every page is a link to our rules. Please reread the last sentence of rule number 4. Excuse me while I go mop up your mess. Smilie
# 3  
Old 12-30-2003
Kornshell convdate

Sorry.

Needed a quick reply and didn't know which forum to ask in.

Apologies
# 4  
Old 12-30-2003
Looking in google for convdate.c, I found this.
# 5  
Old 12-30-2003
Kornshell convdate

Thanks.

However... I found that code and tried it out but got errors regarding the 'extern' keyword.
# 6  
Old 12-30-2003
A few details like what system, what compiler, and what error message would help. But maybe we can solve this anyway.


You need to look at your man page for the getopt function. This will probably be in section 3 of the manual.

man -k getopt
should show all the getopt pages.

man -s3 getopt
or
man 3 getopt
should bring up the page. Look at the page under "synopsis" to see what include file your getopt uses. Add that in. On SunOS it's

#include <stdlib>
# 7  
Old 12-30-2003
Kornshell convdate

Thankyou for your continued help.

Below is the contents of the man file you advised... Is it the libc.a file I need to use? Do I replace all the extern code in the code example you gave me with this file?

I am using an older version of Unix (according to the boss) the version info I have is... IBM RS6000 F50 - AIX Version 4.3.3.


-------------------------------------------------------------------------------
Base Operating System and Extensions Technical Reference, Volume 1
-------------------------------------------------------------------------------

getopt Subroutine

Purpose

Returns the next flag letter specified on the command line.

Library

Standard C Library (libc.a)

Syntax

#include <unistd.h>

int getopt (ArgumentC, ArgumentV, OptionString)

int ArgumentC;

char *const ArgumentV [ ];

const char *OptionString;

extern int optind;

extern int optopt;

extern int opterr;

extern char *optarg;

Description

The optind parameter indexes the next element of the ArgumentV parameter to be
processed. It is initialized to 1 and the getopt subroutine updates it after
calling each element of the ArgumentV parameter.

The getopt subroutine returns the next flag letter in the ArgumentV parameter
list that matches a letter in the OptionString parameter. If the flag takes an
argument, the getopt subroutine sets the optarg parameter to point to the
argument as follows:

o If the flag was the last letter in the string pointed to by an element of
the ArgumentV parameter, the optarg parameter contains the next element of
the ArgumentV parameter and the optind parameter is incremented by 2. If the
resulting value of the optind parameter is not less than the ArgumentC
parameter, this indicates a missing flag argument, and the getopt subroutine
returns an error message.
o Otherwise, the optarg parameter points to the string following the flag
letter in that element of the ArgumentV parameter and the optind parameter
is incremented by 1.

Parameters

ArgumentC Specifies the number of parameters passed to the routine.

ArgumentV Specifies the list of parameters passed to the routine.

OptionString Specifies a string of recognized flag letters. If a letter is
followed by a : (colon), the flag is expected to take a parameter that may or
may not be separated from it by white space.

optind Specifies the next element of the ArgumentV array to be processed.

optopt Specifies any erroneous character in the OptionString parameter.

opterr Indicates that an error has occurred when set to a value other than 0.

optarg Points to the next option flag argument.

Return Values

The getopt subroutine returns the next flag letter specified on the command
line. A value of -1 is returned when all command line flags have been parsed.
When the value of the ArgumentV [optind] parameter is null, *ArgumentV [optind]
is not the - (minus) character, or ArgumentV [optind] points to the "-" (minus)
string, the getopt subroutine returns a value of -1 without changing the value.
If ArgumentV [optind] points to the "- -" (double minus) string, the getopt
subroutine returns a value of -1 after incrementing the value of the optind
parameter.

Error Codes

If the getopt subroutine encounters an option character that is not specified by
the OptionString parameter, a ? (question mark) character is returned. If it
detects a missing option argument and the first character of OptionString is a :
(colon), then a : (colon) character is returned. If this subroutine detects a
missing option argument and the first character of OptionString is not a colon,
it returns a ? (question mark). In either case, the getopt subroutine sets the
optopt parameter to the option character that caused the error. If the
application has not set the opterr parameter to 0 and the first character of
OptionString is not a : (colon), the getopt subroutine also prints a diagnostic
message to standard error.

Examples

The following code fragment processes the flags for a command that can take the
mutually exclusive flags a and b, and the flags f and o, both of which require
parameters.
#include <unistd.h> /*Needed for access subroutine constants*/

main (argc, argv)

int argc;

char **argv;

{

int c;

extern int optind;

extern char *optarg;

.

.

.

while ((c = getopt(argc, argv, "abfSmilie:")) != EOF)

{

switch (c)

{

case 'a':

if (bflg)

errflg++;

else

aflg++;

break;

case 'b':

if (aflg)

errflg++;

else

bflg++;

break;

case 'f':

ifile = optarg;

break;

case 'o':

ofile = optarg;

break;

case '?':

errflg++;

} /* case */

if (errflg)

{

fprintf(stderr, "usage: . . . ");

exit(2);

}

} /* while */

for ( ; optind < argc; optind++)

{

if (access(argv[optind], R_OK))

{

.

.

.

}

} /* for */

} /* main */

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The getopt command.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[SOLVED] String length in kornshell

In the kornshell you can get the length of a string with $ x=abc $ print ${#x} 3 If the current locale is a multibyte locale, like de_AT.UTF-8, you get the length of the string in bytes, not characters: $ x=für $ print ${#x} 4 Is there an easy way to get the length of a... (8 Replies)
Discussion started by: hergp
8 Replies

2. Shell Programming and Scripting

Kornshell finding operating system

This should be really simple but I can't figure it out. :wall: Whats the command to find the operating system version thats running. I need to know if the node my script gets run on is HP-UX or linux or AIX or Oracle (6 Replies)
Discussion started by: Blogger11
6 Replies

3. Shell Programming and Scripting

Kornshell Using a variable in a command

So Here is my code cd $cer_mgr table='hostname' environment='echo $environment' cat mq_$table_$environment_startup.ksh I'm trying to make the results of the command "hostname" into a variable so that i can use it in my cat command. Well what I have is not working. So how do I use that... (1 Reply)
Discussion started by: Blogger11
1 Replies

4. Shell Programming and Scripting

Kornshell grabbing value from file

I have a script right now that I run a command which outputs just one word to a file. Well I need to grab that value and use it in another line of code so... touch oraclesid.txt echo $ORACLE_SID > oraclesid.txt #grab that value sqlplus v500/v500@<value> how do I grab that value from the... (6 Replies)
Discussion started by: Blogger11
6 Replies

5. Shell Programming and Scripting

Execution problem on kornshell

HI, Requirement: I need to pass space between argument value for the paramter "GPG_PUBLIC_UID" but whenever i use single quotes or double quotes while supplying value for the arguments to the script, i see the value of the field "GPG_PUBLIC_UID" is getting splitted and my script fails to... (6 Replies)
Discussion started by: reachaysh
6 Replies

6. Shell Programming and Scripting

Help with Kornshell Script

Hi, I'm a novice at programming and need some help with a kornshell script I've been writting. I have an inputdirectory with all my .shp files. In my input directory the shapefiles are named XXXX_original.shp, XXXX_UPDATE.shp ect. In my .ksh script I have created a for loop which... (2 Replies)
Discussion started by: beery
2 Replies

7. UNIX for Dummies Questions & Answers

[kornshell] Getting the next weekday date

Hi All can anyone help me with this, Im new to kornshell scripting and is trying to get the next weekday to a variable: strDate=%date '+%Y%m%d' // YYYYMMDD strNewDate= :confused: // assuming that current date is 20050812 (friday) then strNewDate will get 20050815 (monday) or if... (1 Reply)
Discussion started by: rs_f01
1 Replies

8. Shell Programming and Scripting

help with Kornshell function

I am trying to write a Kornshell function that takes a string parameter which represents a filename or directory name. The function checks to see if there are any spaces in the filename or directory name and then replaces the spaces with an underscore. The returned value is a filename or directory... (1 Reply)
Discussion started by: ckrieger1
1 Replies

9. Shell Programming and Scripting

Need Help with KornShell script

I need a KornShell script that will, among all the users currently logged on to the system, find a slot of one hour that contains the most number of users. I know how to list all the users currently logged on but how do I do anything with the times that are listed? Please help, thanks. (1 Reply)
Discussion started by: ckrieger1
1 Replies

10. UNIX for Dummies Questions & Answers

Kornshell 93

I've been asked to upgrade from Kornshell 88 to Kornshell 93 on a Solaris 7 box. Since my experience with Unix is limited can anyone point me in the right direction? Specifically, where can I get the files that I need to do the upgrade? Thanks. (1 Reply)
Discussion started by: Ask Me
1 Replies
Login or Register to Ask a Question