ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm starting my adventure in bash scripting, teaching myself. Now i've got alot of basics down, but there are a few things that are iffy, and I haven't came across each function in my tutorial. So here are my questions:
When echo -n "blah" is used, what purpose does -n server?
Using if and elif, what purpose do -z, -x, and ! = or if !  serve?
If you can toss any more - functions out there that will assist me that would be great.
Also, for my first simple program, I am coding an iptables script. I am wanting to have the user input several ports seperated by a space. i.e: 21 22 23 113
All in one line. How would I do this? $1 $2 $3 $4 and so on, or am I way off. I just started yesterday, and I am trying to catch on quickly. Thanks for the help guys.
For your iptables script, do you want to prompt the user for input after the program starts or do you want the user to start the program with the port data as arguments? Either are possible (or both - you could check if command line arguments were provided and if none are given, prompt the user for input).
read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars]
[-d delim] [name ...]
One line is read from the standard input, or from the file
descriptor fd supplied as an argument to the -u option, and the
first word is assigned to the first name, the second word to
the second name, and so on, with leftover words and their
intervening separators assigned to the last name. If there are
fewer words read from the input stream than names, the remain-
ing names are assigned empty values. The characters in IFS are
used to split the line into words. The backslash character (\)
may be used to remove any special meaning for the next charac-
ter read and for line continuation. Options, if supplied, have
the following meanings:
The words are assigned to sequential indices of the
array variable aname, starting at 0. aname is unset
before any new values are assigned. Other name argu-
ments are ignored.
The first character of delim is used to terminate the
input line, rather than newline.
-e If the standard input is coming from a terminal, read-
line (see READLINE above) is used to obtain the line.
read returns after reading nchars characters rather than
waiting for a complete line of input.
Display prompt on standard error, without a trailing
newline, before attempting to read any input. The
prompt is displayed only if input is coming from a ter-
-r Backslash does not act as an escape character. The
backslash is considered to be part of the line. In par-
ticular, a backslash-newline pair may not be used as a
-s Silent mode. If input is coming from a terminal, char-
acters are not echoed.
Cause read to time out and return failure if a complete
line of input is not read within timeout seconds. This
option has no effect if read is not reading input from
the terminal or a pipe.
-u fd Read input from file descriptor fd.
If no names are supplied, the line read is assigned to the
variable REPLY. The return code is zero, unless end-of-file is
encountered, read times out, or an invalid file descriptor is
supplied as the argument to -u.
that is from man read (looks like it brings up a general bash programming man) Hope that helps.