Here you can avoid repeated instructions by putting them between while and do
The last command "true" sets a good exit status (0) so the while loop runs forever, only terminating by the break statements.
greetings,
I have a script that is taking input like this:
a
b
c
d
aa
bb
aaa
bbb
ccc
ddd
and formating it to be like this:
a b c d
aa bb
aaa bbb ccc ddd (4 Replies)
I'm trying to run the logic below but get a `<' is not matched error message when I return a Y or y;
printf "Run this ? : "
read RESP
case $RESP in
Y|y)
cat <<EOF > file
today is Monday
EOF ;;
N|n)
exit 1 ;;
esac
Any ideas? (2 Replies)
i want to get user input like this
please tell which option to chose
1. mango 2. tango 3. rango
if user chooses mango
then it should execute a set of statements and again ask like this
what do you want to do
1.add 2.subtract 3.exit
when i choose exit it should goto my previous... (1 Reply)
i want to get user input like this
please tell which option to chose
1. mango 2. tango 3. rango
if user chooses mango
then it should execute a set of statements and again ask like this
what do you want to do
1.add 2.subtract 3.exit
when i choose exit it should goto my previous menu... (4 Replies)
I was trying to write a simple script which will read a text file and count the number of vowels in the file. My code is given below -
#!/bin/bash
file=$1
v=0
if
then
echo "$0 filename"
exit 1
fi
if
then
echo "$file not a file"
exit 2
fi
while read -n... (14 Replies)
I have the following bash script and it is not accepting the lines
"--"|"--""-")
"--""-"")
while
do
echo "Current Argument is ${1}"
case "$1" in
"--"|"--""-")
echo "Argument is ${1}"
shift # Skip ahead one to the next argument.
... (1 Reply)
Hi Gurus,
I have the below BASH code which does not works for upper case alphabets except Z (upper case Z).
What may be the reason. Also escape sequences like \n, \t, \b, \033(1m \033(0m (For bold letter) are not working.
case $var in
)
echo "Lower case alphabet"
;;
... (7 Replies)
Hi,
I have a script below that is running ssh <host> <command> on some servers.
Below is more or less the script. I have to modify it somehow to get rid of the 'confidential' hostnames
check_log.bash
#!/bin/bash
#
myPID=$$
parse_log ()
{
sub="parse_log"
host=${1}
... (2 Replies)
Discussion started by: newbie_01
2 Replies
LEARN ABOUT PHP
json_last_error
JSON_LAST_ERROR(3) 1 JSON_LAST_ERROR(3)json_last_error - Returns the last error occurredSYNOPSIS
int json_last_error (void )
DESCRIPTION
Returns the last error (if any) occurred during the last JSON encoding/decoding.
PARAMETERS
This function has no parameters.
RETURN VALUES
Returns an integer, the value can be one of the following constants:
JSON error codes
+----------------------------+---------------------------------------------------+
| Constant | |
| | |
| | Meaning |
| | |
| | Availability |
| | |
+----------------------------+---------------------------------------------------+
| | |
| JSON_ERROR_NONE | |
| | |
| | No error has occurred |
| | |
| | |
| | T{ |
| | |
| | JSON_ERROR_DEPTH |
| | |
| | The maximum stack depth has been exceeded |
| | |
| | |
| | T{ |
| | |
| | JSON_ERROR_STATE_MISMATCH |
| | |
| | Invalid or malformed JSON |
| | |
| | |
| | T{ |
| | |
| | JSON_ERROR_CTRL_CHAR |
| | |
| | Control character error, possibly incorrectly |
| | encoded |
| | |
| | |
| | T{ |
| | |
| | JSON_ERROR_SYNTAX |
| | |
| | Syntax error |
| | |
| | |
| | T{ |
| | |
| | JSON_ERROR_UTF8 |
| | |
| | Malformed UTF-8 characters, possibly incorrectly |
| | encoded |
| | |
| | PHP 5.3.3 |
| | |
| | |
| JSON_ERROR_RECURSION | |
| | |
| | One or more recursive references in the value to |
| | be encoded |
| | |
| | PHP 5.5.0 |
| | |
| | |
| JSON_ERROR_INF_OR_NAN | |
| | |
| | One or more NAN or INF values in the value to be |
| | encoded |
| | |
| | PHP 5.5.0 |
| | |
| | |
|JSON_ERROR_UNSUPPORTED_TYPE | |
| | |
| | A value of a type that cannot be encoded was |
| | given |
| | |
| | PHP 5.5.0 |
| | |
+----------------------------+---------------------------------------------------+
EXAMPLES
Example #1
json_last_error(3) example
<?php
// A valid json string
$json[] = '{"Organization": "PHP Documentation Team"}';
// An invalid json string which will cause an syntax
// error, in this case we used ' instead of " for quotation
$json[] = "{'Organization': 'PHP Documentation Team'}";
foreach ($json as $string) {
echo 'Decoding: ' . $string;
json_decode($string);
switch (json_last_error()) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
echo PHP_EOL;
}
?>
The above example will output:
Decoding: {"Organization": "PHP Documentation Team"} - No errors
Decoding: {'Organization': 'PHP Documentation Team'} - Syntax error, malformed JSON
Example #2
json_last_error(3) with json_encode(3)
<?php
// An invalid UTF8 sequence
$text = "xB1x31";
$json = json_encode($text);
$error = json_last_error();
var_dump($json, $error === JSON_ERROR_UTF8);
?>
The above example will output:
string(4) "null"
bool(true)
SEE ALSO json_last_error_msg(3), json_decode(3), json_encode(3).
PHP Documentation Group JSON_LAST_ERROR(3)