Did you see my post update about indirection? In this way you actually pass variables names rather than values, and use the special ${!} notation to expand the value of the variable inside the variable ...
edit: oh nevermind, saw your title "hundreds of vars"... indeed an array is the way to go. target is bash3 or bash4? with bash3 you'd need two separate arrays, one would keep the "key" and the other the "value",
in bash4 you have associative arrays, such that array[key]=val. example for bash3:
Last edited by neutronscott; 04-25-2012 at 03:55 PM..
I have a variable that is outputting a lot of space.
here has been 45 lines returned ...
how can I remove the spaces between the "been and the 45"
CODE:
fil_len=`wc -l < coshb.txt`
if ; then
cat coshb.txt | more
echo " "
echo "There has been ${fil_len} lines... (4 Replies)
hi
I have say five variable.
I would ask the user which one they want me to print and then print accordingly.
TEST_1='10.2.3.4'
TEST_2='11.2.3.5'
TEST_3='12.2.3.5'
TEST_4='13.2.3.5'
TEST_5='14.2.3.5'
print_var()
{
echo "Accessing var num $1"
echo TEST$1
#??? But How do... (6 Replies)
I am modifying an existing script and it has the following line:
export SomeEnvVar=`echo ${SomeLocalVar}`
Why wouldn't it just read:
export SomeEnvVar=${SomeLocalVar}
Is there some reason to use echo instead of a direct assignment? :confused: (2 Replies)
Hi everyone,
I am trying to create a simple batch file to make SQL backups. this part of it works fine. Currently the script can mysql dump the databases, compress them, delete the .sql, compress the individual tar.gz into one larger one, delete the smaller files, encrypt the final tar.gz and... (1 Reply)
$total=500
echo "scale=2; $val1*100/$total" | bc
echo "scale=2; $val2*100*100/$total" | bc
echo "scale=2; $val3*100/$total" | bc
I want to make the above code to be accomplish in a single echo line.
For instance output:21.3, 44.2, 51.6
How to achieve that, some one please help, i just... (5 Replies)
Hi,
i want to create an user-friendly script where you are asked for two numbers. i would like that these two number to be separated with "--" for example, but i can't figure out how to do this.
for example
read -p "Insert lowest and highest value: " min ; echo -n "-- "; read max
so... (3 Replies)
I've testing the following code:
echo test.txt | cut -d . -f1and get the output "text"
So why can't i assign the command to a variable?
VAR='"echo test.txt | cut -d . -f1"'
echo $VAR (5 Replies)
Hi,
I'm new here so I want to say hello to everyone first!
I searched google and this forum for a similar problem, but wasn't successful
#! /bin/bash
I'm trying to output (echo) n lines of a text file to the screen (later into another file).
But I have problem with the sed command, it won't... (1 Reply)
Stumped with the formatting of the awk output when used with variables, e.g.:
awk -F, 'BEGIN {OFS=","} print {$2,$3,$4}' $infile1
produces the desired output (with rows), but when echoing the variable below, the output is one continuous line
var1=$(awk -F, 'BEGIN {OFS=","} print... (4 Replies)
I'm writing a shell script in AIX and using ksh.
I have a scenario where I have a variable A which stores $B.
so when i echo "$A" it prints $B
But I wish to print value stored in var b ie. \a\dir\res\
I wish to store \a\dir\res\ in a third variable C.
later I want to cd into that path :... (1 Reply)
Discussion started by: simpltyansh
1 Replies
LEARN ABOUT PHP
array_intersect_key
ARRAY_INTERSECT_KEY(3) 1 ARRAY_INTERSECT_KEY(3)array_intersect_key - Computes the intersection of arrays using keys for comparisonSYNOPSIS
array array_intersect_key (array $array1, array $array2, [array $...])
DESCRIPTION array_intersect_key(3) returns an array containing all the entries of $array1 which have keys that are present in all the arguments.
PARAMETERS
o $array1
- The array with master keys to check.
o $array2
- An array to compare keys against.
o $...
- A variable list of arrays to compare.
RETURN VALUES
Returns an associative array containing all the entries of $array1 which have keys that are present in all arguments.
EXAMPLES
Example #1
array_intersect_key(3) example
<?php
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
var_dump(array_intersect_key($array1, $array2));
?>
The above example will output:
array(2) {
["blue"]=>
int(1)
["green"]=>
int(3)
}
In our example you see that only the keys 'blue' and 'green' are present in both arrays and thus returned. Also notice that the values for
the keys 'blue' and 'green' differ between the two arrays. A match still occurs because only the keys are checked. The values returned are
those of $array1.
The two keys from the key => value pairs are considered equal only if (string) $key1 === (string) $key2 . In other words a strict type
check is executed so the string representation must be the same.
SEE ALSO array_diff(3), array_udiff(3), array_diff_assoc(3), array_diff_uassoc(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_diff_key(3),
array_diff_ukey(3), array_intersect(3), array_intersect_assoc(3), array_intersect_uassoc(3), array_intersect_ukey(3).
PHP Documentation Group ARRAY_INTERSECT_KEY(3)