I have one more question about the following lines of code:
#!/bin/ksh
if [ "$1" ]; then
num=$1
while [ $num -gt 0 ]; do
echo $num
((num=num-1))
done elif [ "$1" ]; then
num=$1
while [ $num -le 0 ]; do
echo Command line argument must be a positive number and not zero
done
else
echo You must enter one number on the command line
fi
I don't receive any error messages when I run this, but when I enter a negative number on the command line, nothing happens. Any suggestions?
what the script is supposed to do is that I want it to accept an integer and do the following:
1. If it's positive and greater than zero, count down to one
2. If no argument is entered at the command line, then to display a message.
3. If a negative number is entered at the command line, I want a message to display saying to enter a positive number. I just can't get this step to work.
I'm just trying to learn loops and how to nest them inside of each other.
This: if [ "$1 -gt 0" ]; then
is not going to do what you think it might do.
But also, why are there two errors messages? First we reject input because it's not an integer, then we reject input because it's not a positive integer. User's don't like it when the requirements seem to change like that. Error messages really need to go to stderr as a rule anyway. How about:
Now as much as I love structured programming, I would never code like that in real life. I think that an early exit is fine. The real goal of structured programming is easily readable code. I only want to nest one structure inside another when I must. So I would actually go with
And to answer the question before it's asked, ?(+)+([0-9]) is a ksh pattern for a positive integer. ?() optionally matches any of the patterns inside the parentheses, so ?(+) will optionally match a plus sign. +() matches one or more of the patterns inside the parentheses, so +([0-9]) matches one or more numbers.
I am trying to illustrate the reverse order of parameters on the stack when passed to a function in C:
#include <stdio.h>
void p(int p1, int p2, double p3)
{
printf("params:\n"
"1) %p offset = %li\n"
"2) %p offset = %li\n"
... (5 Replies)
Hi folks,
is there any recommendation, especially from a point of performance, about where to place a user-defined function in awk, like in BEGIN{} or if it is only need once at the end in END{}? Or doesn't it matter at all since, awk is so clever and only interprets it once, wherever it is... (3 Replies)
Hi, I am programming in kernel, and I want to use a double linked list that holds infos that every process could access and modify THIS list. So, I suppose it is a 'global' variable since every process(thread) can reach it, I am wondering where to put it? by changing some of the kernel files? (1 Reply)
I have been asked to place 2 (1 NTOP & 1 SNORT) boxes within our network as part of our tool kit for network monitoring and Intrusion detection. Out network is very simplistic and it layed out like this:
internet
|
|
Cisco 1811 Router (8x Layer 2 switch ports)
... (0 Replies)
Hello, everyone!
Is it possible to create a window in X11/WM, but override the position Window Manager sets for the window. I'm not sure how to use 'override_redirect' flag, and what to do in order to use it. But the problem with the flag is also that it probably will disable all decorations... (2 Replies)
I am attempting to create a script that runs automatically upon logging in and opens and places windows in appropriate places. I have the script running such that it starts during login, but I cannot get things how and where I want them. This should be relatively simple, I just can't figure it out... (7 Replies)
Hi,
I'm using xterm and aixterm with Mwm on AIX, and having trouble controlling icon placement when minimising windows. Basically when I run an xterm or aixterm I want to be able to specify where the icon will be if minimised.
The man page mentions the "#geometry Geometry" option to aixterm,... (1 Reply)
Hi,
I'm using xterm and aixterm with Mwm on AIX, and having trouble controlling icon placement when minimising windows. Basically when I run an xterm or aixterm I want to be able to specify where the icon will be if minimised.
The man page mentions the "#geometry Geometry" option to aixterm,... (1 Reply)