You migfht try the following "launcher" script
as a way to get the result you want.
(This assumes the Korn shell, but yout might want
to use some other shell, with slightly different grammar,
for the "if" statement, and a slightly
different grammar for the 'file test", both in lione-15.
Notice - there is a "dot" (period) , followed by
a blank space preceeding your $1
in line # 19. This is REQUIRED, so that
<your-progrqm-name> " will "recognize" the
"command line" variables ($1, $2) of
launcher.
Also, the line-numbers, at the start of each
line of the program are NOT a part of the program
and should be omitted by you.
I put them in so that you can "follow" the lines better.
You can OMIT alll the lines that are comments,
line-3 to line-14, since these lines are there merely to explain what-is-what, in this example.
The 'launcher" program does just what it says
- it "launches" some other program, $1,
(for you) and could
be used to '"launch" alomost any program that
requires a single, input data file., $2.
(See my instructions, at the bottom, about how to use
the "launcher" script.)
=======================================
1 #!/bin/ksh
2 # program: "launcher"
3 # Purpose: execute the
4 # program: <program-name>
5 # If (and only if) file $1
6 # is present.
7 # -----------------------------------------
8 # NOTICE the "dot"-and-space
9 # preceding the <program-name>
10 # so that YOUR (original) program
11 # will use the SAME
12 # "command-line-parameter"
13 # as the "launcher" program.
14 # --------------------------------
15 if [[ -f $1 ]]
16 then
17 # -------------------------------
18 # Now we cqn excute..
19 . $1 $2
20 # ---------------------------------
21 else
22 # We CAN'T execute, since our
23 # file is NOT present
24 echo "File $1: Not found. Can't run now."
25 echo "Exit 99"
26 exit 99
27 fi
=======================================
How you run the program:
launcher <your-program-name> <the-required-file-name> <enter>
=======================================
The <your-program-name> is the "$1", in the
"launcher" program, The
<required-file-name> is the "$2" in the
"launcher" program.
========================================There are other ways to accomplish what you want, also.
You could also put that same "if" test into your
own program, where the "if" statement would
"inclose" the rest of your program, for execution, if
the file were present, and would "exit" if not.
If you want an example of this, ask...
have a nice life, from ernieah
End-of-memo: Best to you..
from ernieah.