There's something to be said for both [[ ... ]] and && || and something against.
Personally I prefer [ ... ] and quotes where needed, and an if [ ... ]; then else where the && part could itself fail.
[[ ]] is testing the test, and leaves you not knowing necessarily why the inner test failed. Was the condition false? Was the variable not declared when it should have been?
I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server..
I have seen some code that may help - but I cant get it working as below:
spawn /usr/bin/ksh
send "telnet x <port_no>\r"
expect "Enter command: "
send "LOGIN:x:x;... (2 Replies)
well i have this code here..and it works fine in kornshell..
#!/bin/ksh
home=c:/..../
input=$1
sed '1,3d' $input > $1.out
line=""
cat $1.out | while read a
do
line="$line $a"
done
echo $line > $1
rm $1.out
however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Hello,
I'm currently messing around with arrays for the first time in scripting (Unix Korn Shell). All I'm trying to do right now before I make things complicated is read through and print out to screen whether the read file is or is not a directory.
Here is my directory:
ls -l
total... (5 Replies)
Hi,
The logic is very simple but I can't seem to make this work in Korn shell.
I need to check two files to make sure there is no errors. Each of the file will have number. For example, first file btt.txt will have 112 which is good. Second file bgg.txt will have 6 which is also good. If I... (4 Replies)
Hi to everybody!
I want to write a simple script in ksh that decrypts and encrypts using the DES algorithm.
There is no builtin function in UNIX : i have found only a function in openssl but i don't understand how to use it.
The script must accept in input the plaitext and the DESKEY in... (2 Replies)
Hi All
I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell.
Some operations like calculation don't work :
cat ${file1} | tail -$((${num1}-${num2})) > ${file2}
Is it possible to activate Korn Shell... (3 Replies)
Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command ..
$ echo $SHELL
yields me
/bin/sh
Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Hi I have the following Korn script having multiple for loops.
#!/bin/ksh
EXPECT=/usr/local/bin/expect
exp_internal
for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do
for i in 01 02 03 04 05 06 07 ; do
for h in 00 01 02 03 04 05 06 07 08 09 10 11 12... (2 Replies)
Hi i have to cut columns 2 to 6 from a file and assign it to arrays ,
The following code works
for ctcol in 2 3 4 5 6;
do
set -A a$ctcol $(cut -d, -f $ctcol test_file)
done
how ever this does not work
for ctcol in {2..6};
do
set -A a$ctcol $(cut -d, -f $ctcol test_file)... (4 Replies)
Hi,
I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically.
When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p)
The output is... (4 Replies)
Discussion started by: Navin_Ramdhami
4 Replies
LEARN ABOUT PHP
assert
ASSERT(3) 1 ASSERT(3)assert - Checks if assertion is FALSESYNOPSIS
bool assert (mixed $assertion, [string $description])
DESCRIPTION assert(3) will check the given $assertion and take appropriate action if its result is FALSE.
If the $assertion is given as a string it will be evaluated as PHP code by assert(3). The advantages of a string $assertion are less over-
head when assertion checking is off and messages containing the $assertion expression when an assertion fails. This means that if you pass
a boolean condition as $assertion this condition will not show up as parameter to the assertion function which you may have defined with
the assert_options(3) function, the condition is converted to a string before calling that handler function, and the boolean FALSE is con-
verted as the empty string.
Assertions should be used as a debugging feature only. You may use them for sanity-checks that test for conditions that should always be
TRUE and that indicate some programming errors if not or to check for the presence of certain features like extension functions or certain
system limits and features.
Assertions should not be used for normal runtime operations like input parameter checks. As a rule of thumb your code should always be
able to work correctly if assertion checking is not activated.
The behavior of assert(3) may be configured by assert_options(3) or by .ini-settings described in that functions manual page.
The assert_options(3) function and/or ASSERT_CALLBACK configuration directive allow a callback function to be set to handle failed asser-
tions.
assert(3) callbacks are particularly useful for building automated test suites because they allow you to easily capture the code passed to
the assertion, along with information on where the assertion was made. While this information can be captured via other methods, using
assertions makes it much faster and easier!
The callback function should accept three arguments. The first argument will contain the file the assertion failed in. The second argument
will contain the line the assertion failed on and the third argument will contain the expression that failed (if any -- literal values such
as 1 or "two" will not be passed via this argument). Users of PHP 5.4.8 and later may also provide a fourth optional argument, which will
contain the $description given to assert(3), if it was set.
PARAMETERS
o $assertion
- The assertion.
o $description
- An optional description that will be included in the failure message if the $assertion fails.
RETURN VALUES
FALSE if the assertion is false, TRUE otherwise.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.4.8 | |
| | |
| | The $description parameter was added. The |
| | $description is also now provided to a callback |
| | function in ASSERT_CALLBACK mode as the fourth |
| | argument. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
Handle a failed assertion with a custom handler
<?php
// Active assert and make it quiet
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
// Create a handler function
function my_assert_handler($file, $line, $code)
{
echo "<hr>Assertion Failed:
File '$file'<br />
Line '$line'<br />
Code '$code'<br /><hr />";
}
// Set up the callback
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
// Make an assertion that should fail
assert('mysql_query("")');
?>
Example #2
Using a custom handler to print a description
<?php
// Active assert and make it quiet
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 0);
assert_options(ASSERT_QUIET_EVAL, 1);
// Create a handler function
function my_assert_handler($file, $line, $code, $desc = null)
{
echo "Assertion failed at $file:$line: $code";
if ($desc) {
echo ": $desc";
}
echo "
";
}
// Set up the callback
assert_options(ASSERT_CALLBACK, 'my_assert_handler');
// Make an assertion that should fail
assert('2 < 1');
assert('2 < 1', 'Two is less than one');
?>
The above example will output:
Assertion failed at test.php:21: 2 < 1
Assertion failed at test.php:22: 2 < 1: Two is less than one
SEE ALSO assert_options(3).
PHP Documentation Group ASSERT(3)