Hey All,
I'm trying to clean up a variable using sed but It dosn't seem to work. I'm trying to find all the spaces and replace them with "\ " (a slash and a space). For Example "Hello World" should become "Hello\ World". But it does nothing. If I put it directly into the command line it works... (3 Replies)
Hi everyone,
I have a simple question to ask :
In a script that I'm writting, I need to create variables on-the-fly.
For instance, for every iterartion of the following loop a var_X variable should be generated :
#!/bin/ksh
a="1 2 3"
for i in $a
do
var_${i}=$i
echo "${var_$i}"
done
... (1 Reply)
I have run into a wall with my iptables firewall scripting.
I am blocking all of the private side IP addresses on the
WAN interface on systems running NAT. However, if the
system is not running NAT and needs to allow access to
the local LAN on the WAN interface, I need to block all
but one of... (2 Replies)
Hello,
i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.
my var1 is a string constructed like this:
filename1 filerev1 filepath1
my var2 is another string constructed like this:
filename2 filerev2 filepath2
when i do... (2 Replies)
Hi,
That might be pretty simple.
How can I generate a variable name and get their value ?
Thanks a lot.
Something like:
>CUSTOMER_NF=26
> object=CUSTOMER
> echo ${object}_NF
CUSTOMER_NF
> echo ${${object}_NF}
ksh: ${${object}_NF}: 0403-011 The specified substitution is... (7 Replies)
file1.ksh
#!/bin/ksh
test5_create="I am a man" # test5 will be dynamic and the value will be passed from command line
a=${1}_create
echo $a # i need the output as "I am a man"
./file1.ksh test5 # i run the script like this
any suggessions guys... (1 Reply)
Hi all.
I'm trying to finish a bash script with the following elements:
ARRAY="blah $ITEM blah blah"
ARRAY="blah blah $ITEM blah bluh"
#ARRAY="...."
# ...the ARRAY elements represent a variable but defined
# syntax and they're all hard-coded in the script.
#(...)
ITEMS='1.0 2.3... (2 Replies)
Hi ,
I have a variable as follows,
Temp=`cat ABC.txt | cut -c5-`
This will yeild a part of the date. say , 200912.
I would like to substitute this variable's value in a filename.
eg: File200912F.zip
when i say File$TempF.zip , it is not substituting.
Any help ?
Thanks in... (2 Replies)
For example I have variable like below
echo $OUTPUT
/some/path/`uname -n`
when I try to use the variable OUTPUT like below
cd $OUTPUT or cd ${OUTPUT}
I am getting bad substituion error message
$ cd $OUTPUT
ksh: cd: bad substitution
$ cd ${OUTPUT}
ksh: cd: bad substitution
... (1 Reply)
Hi,
I have to write a shell script in which I have to substitute a variable within a variable. For example,
var1=aaa
var2=file.$var1.txt
The output should be,
echo $var2
file.aaa.txt
Can someone please help me in getting this. I tried using eval, but it didnt work. I might be using it... (2 Replies)
Discussion started by: grajp002
2 Replies
LEARN ABOUT PHP
array_walk
ARRAY_WALK(3) 1 ARRAY_WALK(3)array_walk - Apply a user supplied function to every member of an arraySYNOPSIS
bool array_walk NULL (array &$array, callable $callback, [mixed $userdata])
DESCRIPTION
Applies the user-defined $callback function to each element of the $array array.
array_walk(3) is not affected by the internal array pointer of $array. array_walk(3) will walk through the entire array regardless of
pointer position.
PARAMETERS
o $array
- The input array.
o $callback
- Typically, $callback takes on two parameters. The $array parameter's value being the first, and the key/index second.
Note
If $callback needs to be working with the actual values of the array, specify the first parameter of $callback as a refer-
ence. Then, any changes made to those elements will be made in the original array itself.
Note
Many internal functions (for example strtolower(3)) will throw a warning if more than the expected number of argument are
passed in and are not usable directly as a $callback.
Only the values of the $array may potentially be changed; its structure cannot be altered, i.e., the programmer cannot add, unset
or reorder elements. If the callback does not respect this requirement, the behavior of this function is undefined, and unpre-
dictable.
o $userdata
- If the optional $userdata parameter is supplied, it will be passed as the third parameter to the $callback.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
ERRORS /EXCEPTIONS
If function $callback requires more parameters than given to it, an error of level E_WARNING will be generated each time array_walk(3)
calls $callback.
EXAMPLES
Example #1
array_walk(3) example
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
function test_alter(&$item1, $key, $prefix)
{
$item1 = "$prefix: $item1";
}
function test_print($item2, $key)
{
echo "$key. $item2<br />
";
}
echo "Before ...:
";
array_walk($fruits, 'test_print');
array_walk($fruits, 'test_alter', 'fruit');
echo "... and after:
";
array_walk($fruits, 'test_print');
?>
The above example will output:
Before ...:
d. lemon
a. orange
b. banana
c. apple
d. fruit: lemon
a. fruit: orange
b. fruit: banana
c. fruit: apple
SEE ALSO array_walk_recursive(3), iterator_apply(3), list(3), each(3), call_user_func_array(3), array_map(3), information about the callback type,
foreach.
PHP Documentation Group ARRAY_WALK(3)