Date: Tue, 6 Aug 2002 08:53:51 -0400 From: "Phil Gates" <p_gates@fuse.net> To: <freebsd-questions@FreeBSD.ORG> Subject: ksh scripting arguments Message-ID: <001501c23d48$50c93b20$5d7e880a@zoomtown.com>
index | next in thread | raw e-mail
[-- Attachment #1 --]
Hi I am writing a ksh script and I am having a problem with a if statement. when I run the script you need to put a argument on the command line. So inside the script I try to make sure that a user is putting a argument on the command line with a if command. The if command is below:
if [$1 -z ]
then
echo "you must put a argument on the command line."
exit
fi
the if statement work fine if there no argument. it will print out the echo statement. On the other handif I put a argument on the command line it will print out the argument and say command is not found.
example of command line and statement
$command argument
print out to screen
argument is not found
I have done ksh scripting on a hp-us machine and I never had this problem before. Has it something how the Unix machine is setup. It seems like the machine does not like any thing that is not a command. It does the same thing if I assign a variable. in the program. So the program is fine if I do no error checking i.e unix command only , but if I use any ksh scripting command it seems to work different.
If anyone can help please email back
Thanks
[-- Attachment #2 --]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2> Hi I am writing a ksh script and
I am having a problem with a if statement. when I run the script you need
to put a argument on the command line. So inside the script I try to make
sure that a user is putting a argument on the command line with a if command.
The if command is below:</FONT></DIV>
<DIV><FONT face=Arial size=2>if [$1 -z ]</FONT></DIV>
<DIV><FONT face=Arial size=2>then</FONT></DIV>
<DIV><FONT face=Arial size=2>echo "you must put a argument on the command
line."</FONT></DIV>
<DIV><FONT face=Arial size=2>exit</FONT></DIV>
<DIV><FONT face=Arial size=2>fi</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>the if statement work fine if there no argument. it
will print out the echo statement. On the other handif I put a argument on
the command line it will print out the argument and say command is not found.
</FONT></DIV>
<DIV><FONT face=Arial size=2>example of command line and statement</FONT></DIV>
<DIV><FONT face=Arial size=2>$command argument</FONT></DIV>
<DIV><FONT face=Arial size=2>print out to screen</FONT></DIV>
<DIV><FONT face=Arial size=2>argument is not found</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I have done ksh scripting on a hp-us machine and I
never had this problem before. Has it something how the Unix machine is
setup. It seems like the machine does not like any thing that is not a
command. It does the same thing if I assign a variable. in the program. So
the program is fine if I do no error checking i.e unix command only , but if I
use any ksh scripting command it seems to work different.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>If anyone can help please email back</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks</FONT></DIV>
<DIV> </DIV></BODY></HTML>
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?001501c23d48$50c93b20$5d7e880a>
