Hi. Im using cat to output the contents of a file, then piping it to my while read loop.In this loop variables get assigned values. However when i try to use the variables outside the loop their values has been reset.I understand about subshells etc. but I have no idea how to "preserve" the... (3 Replies)
Hi,
I was wondering why ls * | echo does not print the contents of the directory to the screen? The way I see it, ls * returns a whole lot of information, and then we pipe all this info to echo, so surely it should all come to our screen!
Is there a serious flaw in my understanding?
... (3 Replies)
Hi All...
Does anyone know how to pipe the output of a "select" statement from a call to Oracle to a file?
ANy ideas woule be greatly appreciated!
Code is as below...
echo "producing CSV file 2..."
sqlplus -s $username/$password@$database<<EOF
set serveroutput on size 1000000
set... (13 Replies)
Hi all,
I would like to send the output of a line in a ksh script to a file, but I need to name the file using a predefined variable:
ls -l > $MYVAR.arc
But what is the correct syntax for achieving this? I can't seem to find the correct syntax for giving the file an extension.
Any... (8 Replies)
Hi All,
I am trying to convert the below Csh code into Perl.
But i have the following error.
Can any expert help ?
Error:
ls: *tac: No such file or directory
Csh
set $ST_file = `ls -rt *$testid*st*|tail -1`;
Perl
my $ST_file = `ls -rt *$testid*st*|tail -1`; (10 Replies)
I would like to pipe "top -n" to a text file, but I get an error:
top: cannot open /dev/kmem
kvm_open: Permission denied
I am a non-root user.
If I could find a way to get this type of output:
"Memory: 2048M real, 1516M free, 4099M swap free"
into a text file, I could further automate... (13 Replies)
Ok, so there is a perl script that runs as a server, on my local host. It tells me which port to use. I want to pipe that output into my browser so I can do the whole thing with a single command. The problem is, I think, that the program doesn't actually exit cause it's running a server, so...... (6 Replies)
Basically I was wondering if any of you know how to pipe the output of ls to a text file? so in my shell script one of the lines is ls but i want to pipe it into a file called directory listing.
Cheers.
I have tried ls | Directorylisting.txt
but it keeps saying " line 7: DirectoryListing.txt:... (9 Replies)
i have a file seperated each line seperated by newline. For example
alpha
beta
gamma
i am trying to replace the newlines to "," but dont want , present at the end of the line so i am trying the below one liner . but not sure whats wrong but its not working
cat myfile | tr -s '\n' ',' | sed... (9 Replies)
Hey Guys. Below is the code I am using to pipe a value into a variable. When I tried it says the following
xargs: :HEX:: No such file or directory
Not sure what it means. Can anyone please help me figure this out.
Below is the code I am using. (It echo's out just fine)
sed -n... (1 Reply)
Discussion started by: eldan88
1 Replies
LEARN ABOUT PHP
unset
UNSET(3) 1 UNSET(3)unset - Unset a given variableSYNOPSIS
void unset (mixed $var, [mixed $...])
DESCRIPTION unset(3) destroys the specified variables.
The behavior of unset(3) inside of a function can vary depending on what type of variable you are attempting to destroy.
If a globalized variable is unset(3) inside of a function, only the local variable is destroyed. The variable in the calling environment
will retain the same value as before unset(3) was called.
<?php
function destroy_foo()
{
global $foo;
unset($foo);
}
$foo = 'bar';
destroy_foo();
echo $foo;
?>
The above example will output:
bar
To unset(3) a global variable inside of a function, then use the $GLOBALS array to do so:
<?php
function foo()
{
unset($GLOBALS['bar']);
}
$bar = "something";
foo();
?>
If a variable that is PASSED BY REFERENCE is unset(3) inside of a function, only the local variable is destroyed. The variable in the
calling environment will retain the same value as before unset(3) was called.
<?php
function foo(&$bar)
{
unset($bar);
$bar = "blah";
}
$bar = 'something';
echo "$bar
";
foo($bar);
echo "$bar
";
?>
The above example will output:
something
something
If a static variable is unset(3) inside of a function, unset(3) destroys the variable only in the context of the rest of a function. Fol-
lowing calls will restore the previous value of a variable.
<?php
function foo()
{
static $bar;
$bar++;
echo "Before unset: $bar, ";
unset($bar);
$bar = 23;
echo "after unset: $bar
";
}
foo();
foo();
foo();
?>
The above example will output:
Before unset: 1, after unset: 23
Before unset: 2, after unset: 23
Before unset: 3, after unset: 23
PARAMETERS
o $var
- The variable to be unset.
o $...
- Another variable ...
RETURN VALUES
No value is returned.
EXAMPLES
Example #1
unset(3) example
<?php
// destroy a single variable
unset($foo);
// destroy a single element of an array
unset($bar['quux']);
// destroy more than one variable
unset($foo1, $foo2, $foo3);
?>
Example #2
Using (unset) casting
(unset) casting is often confused with the unset(3) function. (unset) casting serves only as a NULL-type cast, for completeness. It
does not alter the variable it's casting.
<?php
$name = 'Felipe';
var_dump((unset) $name);
var_dump($name);
?>
The above example will output:
NULL
string(6) "Felipe"
NOTES
Note
Because this is a language construct and not a function, it cannot be called using variable functions.
Note
It is possible to unset even object properties visible in current context.
Note
It is not possible to unset $this inside an object method since PHP 5.
Note
When using unset(3) on inaccessible object properties, the __unset() overloading method will be called, if declared.
SEE ALSO isset(3), empty(3), __unset(), array_splice(3).
PHP Documentation Group UNSET(3)