Is it about sorting of arguments that are given to a script or a script function?
The sorting of arguments requires an explicit sorting, either with an external sort command or with a sort function.
A newline is an obstacle for the external sort command, unless sort understands -t $'\0' or similar tricks.
A shell function can do it, as shown by the following sample:
Proper quoting of variables in command arguments is important! Only then all special characters are treated normal, even newline characters.
--
You haven't provided your shell script yet. So maybe my assumptions were totally wrong...
Hi, I'm a pretty big fan of BASH scripting. I've got a bunch I use for random things and lately a couple issues have been plaguing me.
Both are somewhat related, in that they deal with filenames with spaces and "escaped" characters and with launching a program with command line arguements... (5 Replies)
Hi I have 2 files a.c and a.bak where I changed long to int using awk script.
I want to get the list of functions whose parameters got modified
for eg: fun ( long a, long b ) might be changed to fun ( int a, int b ) (1 Reply)
Hello,
I've got next problem:
I want to examine at the beginning of a script in an if loop that:
1. Is there 4 parameters given
2. If first state is true then: is there switches -e and -d?
3. At the end, how can i indentify them as variebles regardlees to its order.
I was thinking like... (2 Replies)
Hi, I am trying to do this thing useing my shell bash ( sorry for my english )
I have in a file 63 hostnames, i wanna ask to the DHCP admin, to reserv that reserves 63 IP addresses of this hosts, using their mac address.
I have thinked this script:
for ((i=1;i<63;i++)); do
arp $(head... (10 Replies)
Hi,
So I have a web page that has some drop down boxes with a whole bunch of entries. Unfortunately, they have been added over time and started from a small list and is now extremely messy. I'm looking to write script so I can just copy in the section of the HTML code and have it sorted for... (6 Replies)
I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
In a Bash script I used getopts command to let a user does something regards to the selected options. The question is: How do you find out what is the name of the file that user inserted in the command line like the following:
The good part is this file is always the last argument in the... (2 Replies)
Hi,
I have a script which will be executed using the below command,
bin/nutch crawl urls -dir /data/test/
bin/nutch - Script file
crawl, urls, /data/test/ - Parameters
-dir - Option
The above script should executed from a shell script named test.sh. I have the below code to execute... (2 Replies)
Hi,
I have 4 parameters passed to my shell and i validate if all four are entered using the following snippet:
if
then echo "Not entered"
else echo "entered"
fi
I get the following output as 'Not entered even when i enter the values for all prompts.
Please advise.
Thanks. (5 Replies)
Discussion started by: Jesshelle David
5 Replies
LEARN ABOUT SUNOS
qsort
qsort(3C) Standard C Library Functions qsort(3C)NAME
qsort - quick sort
SYNOPSIS
#include <stdlib.h>
void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *));
DESCRIPTION
The qsort() function is an implementation of the quick-sort algorithm. It sorts a table of data in place. The contents of the table are
sorted in ascending order according to the user-supplied comparison function.
The base argument points to the element at the base of the table. The nel argument is the number of elements in the table. The width
argument specifies the size of each element in bytes. The compar argument is the name of the comparison function, which is called with two
arguments that point to the elements being compared.
The function must return an integer less than, equal to, or greater than zero to indicate if the first argument is to be considered less
than, equal to, or greater than the second argument.
The contents of the table are sorted in ascending order according to the user supplied comparison function.
USAGE
The qsort() function safely allows concurrent access by multiple threads to disjoint data, such as overlapping subtrees or tables.
EXAMPLES
Example 1: Program sorts.
The following program sorts a simple array:
#include <stdlib.h>
#include <stdio.h>
static int
intcompare(const void *p1, const void *p2)
{
int i = *((int *)p1);
int j = *((int *)p2);
if (i > j)
return(1);
if (i < j)
return (-1);
return(0);
}
int
main()
{
int i;
int a[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
size_t nelems = sizeof (a) / sizeof (int);
qsort((void *)a, nelems, sizeof (int), intcompare);
for (i = 0; i < nelems; i++) {
(void) printf("%d ", a[i]);
}
(void) printf("
");
return(0);
}
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO sort(1), bsearch(3C), lsearch(3C), string(3C), attributes(5), standards(5)NOTES
The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being
compared.
The relative order in the output of two items that compare as equal is unpredictable.
SunOS 5.10 6 Dec 2004 qsort(3C)