08-07-2008
$# is the number of parameters given to the script - [ ] tests whether the number of parameters equals 1 - if not one then display the usage example.
$# = parameter count
-ne = not equal for integers
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
zsh 4.3.4% cat file
ACFCFACCACARCSHFARCVJVASTVAJFTVAJVGHBAJ
zsh 4.3.4% cat file1
A
C
F
R
zsh 4.3.4% <file1 while read;do printf "%s=%d\n" "$REPLY" "${#$(<file)//}";done
A=9
C=7
F=4
R=2
That was the previous post.
But , can anybody can explain me in detail about this line
zsh... (2 Replies)
Discussion started by: dummy_needhelp
2 Replies
2. Shell Programming and Scripting
I did not understand what is ${0##/}
PGM=${0##/}
TMP=/tmp/${PGM}.$$
Please explain me. (2 Replies)
Discussion started by: gadege
2 Replies
3. Shell Programming and Scripting
could u please convert the below statement to shell script
----------
logdir=/smp/dyn/logfiles/cpm/pgm/pgIm
$logdir = $logdir ."/pgIm${toDate}*";
----
could u please explain the below clearly
grep -i adding $logdir | grep -iv equation | awk '{print \$NF}' | sort -u | sed -e... (1 Reply)
Discussion started by: mail2sant
1 Replies
4. UNIX for Dummies Questions & Answers
if
then
echo "Syntax: $0 <sid> <COLD/HOT> <DEST>"
exit
fi
if --------------what does this mean???
echo "Syntax: $0 <sid> <COLD/HOT> <DEST>"---pls explain this as well (2 Replies)
Discussion started by: appsdba.nitin
2 Replies
5. Shell Programming and Scripting
hi all i have an example i want one help me to understand cause i tried to test it but almost fail and i don't know how can i solve this problem " the main idea to read from two files and replace something from one to another " but i don't understand why it fail all time
$ cat main.txt... (4 Replies)
Discussion started by: maxim42
4 Replies
6. Homework & Coursework Questions
1. The problem statement, all variables and given/known data:
I have a retake assignment to complete for my computer networks and OS class. This isn't really my area, had I known last year I could have swapped it for a different module I would have done so. I'm determined to get through it... (6 Replies)
Discussion started by: Squall Moogle
6 Replies
7. Shell Programming and Scripting
I'm trying to follow a script and I see it begins with this:
if ; then
if ; then
print "blah $0 blah blah "
exit
fi
fi
What does $# mean? I found out that $1 refers to the shell environment and the last argument that was entered or passed in the previous command. I couldn't find $#... (2 Replies)
Discussion started by: MaindotC
2 Replies
8. Shell Programming and Scripting
why the case 2 will happen ? , ' should stop the history substitution ,shouldn't it?
case 1
# echo "123"|sed '/123/!d'
123
case 2
# echo "123
> 456
> 1
> "|sed '/123/!d'
-bash: !d': event not found
case 3
# echo "123
> 456
> 12
> "|sed '/123/'\!d
123
# bash --version (1 Reply)
Discussion started by: justlooks
1 Replies
9. Shell Programming and Scripting
Can someone do me a favour and explain the following for me:
((r=$RANDOM%$n+1))
I know what $RANDOM does but what is % sign and what does it do with %$n+1? (2 Replies)
Discussion started by: bashily
2 Replies
10. UNIX for Dummies Questions & Answers
Hi friends! I'm learning UNIX and I have a small question. Working with Shell, i put the name of one executable (in c language) + one number and it says this:
$ gcc misterioso_4.c
$ ./misterioso_4 6
got: ,
I can not find an answer in the manual because I havent applied any variable.... (5 Replies)
Discussion started by: dakota
5 Replies
LEARN ABOUT PLAN9
getflags
GETFLAGS(9.2) GETFLAGS(9.2)
NAME
getflags, usage - process flag arguments in argv
SYNOPSIS
#include <libg.h>
#include <fb.h>
int getflags(int argc, char *argv[], char *flags)
int usage(char *tail)
extern char **flag[], cmdline[], *cmdname, *flagset[];
DESCRIPTION
Getflags digests an argument vector argv, finding flag arguments listed in flags. Flags is a string of flag letters. A letter followed by
a colon and a number is expected to have the given number of parameters. A flag argument starts with `-' and is followed by any number of
flag letters. A flag with one or more parameters must be the last flag in an argument. If any characters follow it, they are the flag's
first parameter. Otherwise the following argument is the first parameter. Subsequent parameters are taken from subsequent arguments.
The global array flag is set to point to an array of parameters for each flag found. Thus, if flag -x was seen, flag['x'] is non-zero, and
flag['x'][i] is the flag's ith parameter. If flag -x has no parameters flag['x']==flagset. Flags not found are marked with a zero. Flags
and their parameters are deleted from argv. Getflags returns the adjusted argument count.
Getflags stops scanning for flags upon encountering a non-flag argument, or the argument --, which is deleted.
Getflags places a pointer to argv[0] in the external variable cmdname. It also concatenates the original members of argv, separated by
spaces, and places the result in the external array cmdline.
Usage constructs a usage message, prints it on the standard error file, and exits with status 1. The command name printed is argv[0].
Appropriate flag usage syntax is generated from flags. As an aid, explanatory information about flag parameters may be included in flags
in square brackets as in the example. Tail is printed at the end of the message. If getflags encountered an error, usage tries to indi-
cate the cause.
EXAMPLES
main(int argc, char *argv[]){
if((argc=getflags(argc, argv, "vinclbhse:1[expr]", 1))==-1)
usage("[file ...]");
}
might print:
Illegal flag -u
Usage: grep [-vinclbhs] [-e expr] [file ...]
SOURCE
/sys/src/libfb/getflags.c
SEE ALSO
ARG(2)
DIAGNOSTICS
Getflags returns -1 on error: a syntax error in flags, setting a flag more than once, setting a flag not mentioned in flags, or running out
of arguments while collecting a flag's parameters.
GETFLAGS(9.2)