Hello guys.
In my script, i have the following code:
echo "The tarfile contains these directorys"
tar -tf file.tar > tarlist.txt
cat tarlist | awk -F/ '{print $1 "/" $2}' | nl
echo "Enter path of the directory you want to extract or just press enter to extract everything: "
read path... (1 Reply)
I need to check if $1 or $2 are empty before continuing but I don't know if bash has any logic of the sort. This is what I'm looking for - except that "and" doesn't seem to work.
if and ;then
...
Thank you! :D (4 Replies)
hi all i am trying to save an awk value into an array in bash:
total=`awk '{sum+=$3} END {print sum}' "$count".txt"`
((count++))
the above statement is in a while loop..
$count is to keep track of file numbers (1.txt,2.txt,3.txt,etc.)
i get the following error:
./lines1:... (1 Reply)
Apologies for the utter triviality of this question, but we all have to start somewhere! I've also tried searching but this question is pretty vague so I didn't (a) really know what to search for or (b) get many relevant hits to what I did search for.
Anyway, I'm in the process of self-teaching... (1 Reply)
Hi!
Been working on a script and I've been having a problem. I've finally narrowed it down to this variable I'm setting:
servername=$(awk -v FS=\/ '{ print $7 } blah.txt | sed 's\/./-/g' | awk -v FS=\- '{print $1}')"
This will essentially pare down a line like this:
... (7 Replies)
Hi gurus,
I need to create arrays from variables, via a loop.
The issue I have is with the array name creation. How do I use a variable to define an array?
I want to do something like
declare -a $H
where $H is my loop variable.
I then need to add items to each array I've created,... (3 Replies)
I am new to ksh scripting, specially array. How do i get values from an array and set the value as variable and pass those variables to the different functions??
someone taught me how to get input from a file with have columns i need to read, but now i doesnt know how to set those value to be a... (7 Replies)
Hi,
Will following set up work in bash script? I've got errors if assigning following binary command to a variable. But on the other hand, COMMAND="ls" works. Any explanation please? How can I assign binary command to a variable COMMAND then I can just call ${COMMAND}?
COMMAND="rsync"... (3 Replies)
Hello,
I have a simple task and I am having some trouble with the syntax. I have a variable with an assigned value,
CMD_STRING='-L 22 -s 0 -r -O -A i -N 100 -n'
I would like to add that variable to an array. As far as I have been able to look up, the syntax should be something like,
... (4 Replies)
Right, now that I've finally worked out this website, I'll ask my question!
I am having an absolute nightmare with NFS on AIX. I have used it many times, and I know what I'm doing, however I cannot fathom what is going on here. I have 2 LPARs, sitting on the same physical host. They are... (12 Replies)
Discussion started by: tmooredba
12 Replies
LEARN ABOUT PHP
list
LIST(3) 1 LIST(3)list - Assign variables as if they were an arraySYNOPSIS
array list (mixed $var1, [mixed $...])
DESCRIPTION
Like array(3), this is not really a function, but a language construct. list(3) is used to assign a list of variables in one operation.
PARAMETERS
o $var1
- A variable.
RETURN VALUES
Returns the assigned array.
EXAMPLES
Example #1
list(3) examples
<?php
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.
";
// Listing some of them
list($drink, , $power) = $info;
echo "$drink has $power.
";
// Or let's skip to only the third one
list( , , $power) = $info;
echo "I need $power!
";
// list() doesn't work with strings
list($bar) = "abcde";
var_dump($bar); // NULL
?>
Example #2
An example use of list(3)
<table>
<tr>
<th>Employee name</th>
<th>Salary</th>
</tr>
<?php
$result = $pdo->query("SELECT id, name, salary FROM employees");
while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) {
echo " <tr>
" .
" <td><a href="info.php?id=$id">$name</a></td>
" .
" <td>$salary</td>
" .
" </tr>
";
}
?>
</table>
Example #3
Using nested list(3)
<?php
list($a, list($b, $c)) = array(1, array(2, 3));
var_dump($a, $b, $c);
?>
int(1)int(2)int(3)
Example #4
Using list(3) with array indices
<?php
$info = array('coffee', 'brown', 'caffeine');
list($a[0], $a[1], $a[2]) = $info;
var_dump($a);
?>
Gives the following output (note the order of the elements compared in which order they were written in the list(3) syntax):
array(3) {
[2]=>
string(8) "caffeine"
[1]=>
string(5) "brown"
[0]=>
string(6) "coffee"
}
NOTES
Warning
list(3) assigns the values starting with the right-most parameter. If you are using plain variables, you don't have to worry about
this. But if you are using arrays with indices you usually expect the order of the indices in the array the same you wrote in the
list(3) from left to right; which it isn't. It's assigned in the reverse order.
Warning
Modification of the array during list(3) execution (e.g. using list($a, $b) = $b) results in undefined behavior.
Note
list(3) only works on numerical arrays and assumes the numerical indices start at 0.
SEE ALSO each(3), array(3), extract(3).
PHP Documentation Group LIST(3)