× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I was uncler. I was referring to Qshell.

This started out simple. I want to run an sftp to generate a lit of files on remote server. Then, use n sftp to get the file, one at a time. In MOST
cases, there will only be one file to retrieve. However, the site has a
history of going down. Thus, with a job submitted to batch, the site could be
down or not.

The file or files would subsequently need to be copied from a stream file to a
database file. CPYFRMIMPF seems to work nice for this. Finally, an RPG
program reads that files and writes to the actual database file.

Obviously, I don't actually need to check for a missing parameter. Maybe it is
not even a good idea. Better approach might be to have two functions in the
script, one to get the list and the second to get the files.

something like this:
for i in `get_file_list`
do
get_file $i
system(CPYFRMIMPF...........)
done

And the CL that calls this QSH script would then invoke the RPG program to
finish up.

My initial thought was if a function was not supplied, then it would return the
lit of files. But, it is just as easy to use two functions, and likely clearer
as well.


I think I made the issue more complicated than it needed to be.

But, simple question is this:

I thought there was a $something that returned the number of arguments supplied.
I can't remember what the character following the $ is that had the argument
count.

If I needed to write a script that needed to default to something if a single
argument was omitted, what is that function? For instance cal does current
month and cal with 2009 does the given year.

Really not an issue, after more thought. I mislaid my K&P book years ago that
detailed the various values.

John McKee


Quoting Scott Klement <midrange-l@xxxxxxxxxxxxxxxx>:

Hi John,

I am drawing a blank here.
How do I test for the absence of of a parameter in a shell script?

I'm assuming you by "shell script" you mean either QShell or Bourne
shell. If that's wrong, please tell me so.

It depends on what you mean by "absence". Consider the following
command-line that runs a script of mine:

runxfer.sh -u klemscot -p bigboy sftp.klements.com

If I changed it to look as follows, what would be "absent"?

runxfer.sh -u klemscot sftp.klements.com

Would I say that the 3rd and 4th parameters weren't passed? Because,
technically, the 3rd parameter WAS passed... it just isn't -p anymore.
So it's really a hard question to answer. It really depends on the
paradigm in which you wrote your script.

how about if I did this:

runxfer.sh -u klemscot -p "" sftp.klements.com

Now I have the same number of parameters as my original example, but one
of them is an empty string. Does that count as being passed or not?

So, really, the first thing you need to decide... how are you handlign
parameters? Are you using option flags with values? Or is it purely
positional?

Then you need to decide what is considered "absence"? If a string is
passed, but is blank, is that considered absent?

Sorry. I hate complicating things -- but I want to make sure I'm
answering the right question.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.






As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.