×
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.
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.
As an Amazon Associate we earn from qualifying purchases.