Hi all,
My script has 2 mandatory and 1 optional paramter. If the third parameter(optional) one is null the it should take a default value say 3. Can any one please write a simple code.
sh test.sh 1 2 3
var1=$1
var2=$2
if
then
var3=3
fi
echo " the third variable $var3"
... (1 Reply)
I am passing a file name as a parameter to shell script
the parameter is getfile.txt.gpg
how do i process this parameter to get name like getfile.txt only and eleminate the .gpg text??
Thanks in advance (2 Replies)
Hi,
I will pass 3 parameters for a script.I have to check the file name and create a new file name with time stamp.
the parameters which i'm passing are
/dir/stg/filename.txt
/dir/path/head.txt
/dir/path/tail.txt
Now i have to check filename like :
if it is a.txt i have to create... (2 Replies)
hi all,
i have a ksh script that takes up to 3 parameters -- only 2 of which are required. what's the simplest way to check if the user passed 2 or 3 parameters?
if 3 parameters are not null then
do this
elif 2 parameters are not null then
do this
else
echo "you need at least 2... (5 Replies)
Hi,
I am executing a shell script which takes a string as a parameter.
The scipt should validate the string and create the directoy with the name of specfied string.
The following is the specified command and its parameter.
test.sh "abc abc"
The shell script is not able to identify... (4 Replies)
i got a file called Pass1, and then i need to passed a number to my script with the '-p pass_mark' option.
Example type
Pass1 -p 18
to pass 18 to my script for comparing things, so how can i do it? (7 Replies)
Hello Everyone,
I have been trying to complete a shell script where, I need to increment the date depending on the file (depending on the date) availability on the remote server.
i.e.
Basically, I will be passing a counter (like parameter 1 or 2 or 3 or 4).
First I will check for the... (1 Reply)
Hi
I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/
Can anyone please help me on this? (3 Replies)
Hi,
I have the following files.
->cat scr.sh
export TMP_DIR=/home/user/folder1
export TMP_DIR_2=/home/user/folder2
while read line
do
cat "$line"
done<file_list.dat
------------------------
-> cat file_list.dat
$TMP_DIR/file1.txt
$TMP_DIR_2/file2.txt
---------------------------
-> cat... (6 Replies)
Discussion started by: barath
6 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)