BASH is a string language with weak types, so copying an entire array around like that means having to handle it as a string.
There is an operator to turn an array into one string: "${ARR[*]}" But how're you going to do that when all you have is the name of the array, not the array itself? "${!ARR[*]}" doesn't work, the precedence is wrong, and you can't put the[*] outside it to do it backwards. You could shove it all into an eval, which can accomplish any weird syntax you want, but would be difficult. And then you have to turn it back into an array, wrapping it in another layer of stuff.
It's easy to turn a string into an array, though, and BASH has the ! operator to turn a variable name into a variable string. So why not keep your data as strings for easy retrieval?
Dear Friends,
I am doing a sh shell script , But I dont have any idea how to read value from user Keyboard and store them to an array .. Is it possible or not I am not also sure in sh shell script ?
EX:-
#! /bin/sh
read DATA
echo "DATA -" $DATA
echo "DATA -" $DATA
echo "DATA... (7 Replies)
Hi all,
I wrote a script that reads inputs from user and store in array named "input". The number of elements in the array is not fixed - determined only after user exit the while loop that reads the array values :
x=1
echo "Enter first value"
read input
while } != "exit" ]
do
... (1 Reply)
I want to ask the user to enter an X amount of file names. I want to put those names into an array and then loop back through them to verify they are in the directory. 1st- How would I assign the value to an array and what is the correct syntax. 2nd- how would i reference that array after I... (3 Replies)
Hi,
I have a piece of code as follows:
i=0
while read LINE
do
var = "$LINE"
i=$((i+1))
echo "${var}"
done < file
I want to assign value to the array var.
However, when i execute the script i get a error.
Please can you help me know what i am missing.
I ultimately want to... (2 Replies)
Hi all,
I am just wondering is this (below code) valid in programming
int xx = 10110;
int i;
long yy = {1,2,3,4,5,6,7,8,xx};
I compiled this using gcc will all working option successfully without getting any warning or error. I didn't see this kind of code in my past... (7 Replies)
Hi all ,
I have a string like para1#para2#para3
i want to assign para1 as first element para2 as second and so on
i tried
IFS=#
set -A array para1#para2#para3
echo ${array}
para1 para2 para3
i want echo ${array}
para1 (2 Replies)
Hi, How to create array every time user input and store user input and display all array
print " Enter input "
my @input = split(' ', $input)
chmop($input = <STDIN>;
foreach ($input)
{
@array= @input;
}
print @array"\n"; (1 Reply)
I want to create an array which can store the strings from the user input in shell script .
example :-
I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Hello All,
Can you please help me with the below.
#!/bin/bash
ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1"
ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Hello,
I am running under ubuntu1 14.04 and I have a script which is sending given process names to vanish so that I'd see less output when I run most popular tools like top etc in terminal window. In usual method it works.
Whenever I restart the system, I have to enter the same data from... (2 Replies)
Discussion started by: baris35
2 Replies
LEARN ABOUT NETBSD
scandir
SCANDIR(3) BSD Library Functions Manual SCANDIR(3)NAME
scandir, alphasort -- scan a directory
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/types.h>
#include <dirent.h>
int
scandir(const char *dirname, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const void *, const void *));
int
alphasort(const void *d1, const void *d2);
DESCRIPTION
The scandir() function reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the num-
ber of entries in the array. A pointer to the array of directory entries is stored in the location referenced by namelist.
The select parameter is a pointer to a user supplied subroutine which is called by scandir() to select which entries are to be included in
the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be
included in the array. If select is null, then all the directory entries will be included.
The compar parameter is a pointer to a user supplied subroutine which is passed to qsort(3) to sort the completed array. If this pointer is
null, the array is not sorted.
The alphasort() function is a routine which can be used for the compar parameter to sort the array alphabetically.
The memory allocated for the array can be deallocated with free(3), by freeing each pointer in the array and then the array itself.
DIAGNOSTICS
Returns -1 if the directory cannot be opened for reading or if malloc(3) cannot allocate enough memory to hold all the data structures.
SEE ALSO directory(3), dirent(3), malloc(3), qsort(3)STANDARDS
The scandir() and alphasort() functions conform to IEEE Std 1003.1-2008 (``POSIX.1'').
HISTORY
The scandir() and alphasort() functions appeared in 4.2BSD.
BSD April 29, 2010 BSD