11-16-2019
I'd trust the system when it complains a file not residing where it looks for it.
Did you make very sure that file exists?
What happens in your script is that
bash's
mapfile /
readarray builtin is duplicated by using a "command substitution".
man bash:
Quote:
The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).
Above mentioned builtins serve the same purpose, offer some more options, and don't rely on the deprecated, dangerous
eval command.
man bash:
Quote:
mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from the standard input into the indexed array variable array
Why don't you just abandon the function?
Last edited by RudiC; 11-16-2019 at 03:30 PM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a little script to help me manage a gallery of image files. It makes symbolic links to every file in and below the current directory, placing them in a target directory which is passed to the script as a parameter. Unfortunately, the script pukes when I pass a parameter that contains... (4 Replies)
Discussion started by: TanRanger
4 Replies
2. UNIX for Advanced & Expert Users
If have
var='$variable'
how can I expand $variable.
I have tried many thing like duble quotes/braces etc, but nothing worked.
I need the solution ASAP. (2 Replies)
Discussion started by: Bsk
2 Replies
3. UNIX for Dummies Questions & Answers
Hi,
The following code finds the line containing fruits in test.txt and replaces instances of apple with banana.
ed -s test.txt <<< $'/fruits/s/apple/banana/g\nw'
What I want to do is put variables in the place of fruits, apple and banana.
I have tried replacing ' with " to get... (2 Replies)
Discussion started by: de_la_espada
2 Replies
4. Shell Programming and Scripting
Hi,
I need some direction with the following. The below code is semi-psuedo code which will hopefully make it easier to understand what I am trying to achieve:
for i in `echo ${testarray
}`
do
let c=c+1
eval "first$c=$i"
while... (4 Replies)
Discussion started by: yonderboy
4 Replies
5. Shell Programming and Scripting
Hello,
so i'm making a script, using dynamic variables and trying to expand them. So far it hasn't worked out too well so it seems that I need some help from you, the elite.
Example:
#!/bin/sh
counter=0
until (($counter>5))
counter2=1
until (($counter2>6)); do
if ;... (5 Replies)
Discussion started by: TehOne
5 Replies
6. Shell Programming and Scripting
Hi Guys,
I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need.
I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles.
... (3 Replies)
Discussion started by: gazza-o
3 Replies
7. Shell Programming and Scripting
anyone has any info on why this is complaining???
vivek@vivek-c5e55ef2e ~/TAC
$ zoneCounter=1
vivek@vivek-c5e55ef2e ~/TAC
$ optUsage1=23%
vivek@vivek-c5e55ef2e ~/TAC
$ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>"
-bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies
8. Shell Programming and Scripting
anyone has any info on why this is complaining???
vivek@vivek-c5e55ef2e ~/TAC
$ zoneCounter=1
vivek@vivek-c5e55ef2e ~/TAC
$ optUsage1=23%
vivek@vivek-c5e55ef2e ~/TAC
$ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>"
-bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies
9. Shell Programming and Scripting
My OS is Linux (kernel 4.08.something) and AIX (7100-04-01-1543), the used ksh versions are:
ksh88: Version M-11/16/88f (AIX)
ksh93: Version M 93t+ 2009-05-01 (AIX), Version M 93u (Linux)
When writing a parser for stanza files in ksh i encountered a rather strange behavior. Here is a... (4 Replies)
Discussion started by: bakunin
4 Replies
10. UNIX for Beginners Questions & Answers
I pass an argument to bash as run. The first command in green executes as expected, however the second in blue fails as the $run does not expand. I tried to escape the variable with \ thinking the quotes were making the literal translation and also "${run}" but both did not work to expand the... (3 Replies)
Discussion started by: cmccabe
3 Replies
COUNT(3) 1 COUNT(3)
count - Count all elements in an array, or something in an object
SYNOPSIS
int count (mixed $array_or_countable, [int $mode = COUNT_NORMAL])
DESCRIPTION
Counts all elements in an array, or something in an object.
For objects, if you have SPL installed, you can hook into count(3) by implementing interface Countable. The interface has exactly one
method, Countable::count, which returns the return value for the count(3) function.
Please see the Array section of the manual for a detailed explanation of how arrays are implemented and used in PHP.
PARAMETERS
o $array_or_countable
- An array or Countable object.
o $mode
- If the optional $mode parameter is set to COUNT_RECURSIVE (or 1), count(3) will recursively count the array. This is particu-
larly useful for counting all the elements of a multidimensional array.
Caution
count(3) can detect recursion to avoid an infinite loop, but will emit an E_WARNING every time it does (in case the array
contains itself more than once) and return a count higher than may be expected.
RETURN VALUES
Returns the number of elements in $array_or_countable. If the parameter is not an array or not an object with implemented Countable inter-
face, 1 will be returned. There is one exception, if $array_or_countable is NULL, 0 will be returned.
Caution
count(3) may return 0 for a variable that isn't set, but it may also return 0 for a variable that has been initialized with an empty
array. Use isset(3) to test if a variable is set.
EXAMPLES
Example #1
count(3) example
<?php
$a[0] = 1;
$a[1] = 3;
$a[2] = 5;
$result = count($a);
// $result == 3
$b[0] = 7;
$b[5] = 9;
$b[10] = 11;
$result = count($b);
// $result == 3
$result = count(null);
// $result == 0
$result = count(false);
// $result == 1
?>
Example #2
Recursive count(3) example
<?php
$food = array('fruits' => array('orange', 'banana', 'apple'),
'veggie' => array('carrot', 'collard', 'pea'));
// recursive count
echo count($food, COUNT_RECURSIVE); // output 8
// normal count
echo count($food); // output 2
?>
SEE ALSO
is_array(3), isset(3), strlen(3).
PHP Documentation Group COUNT(3)