logo
down
shadow

What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?


What's wrong with my WHILE-DO loop, or why my script can't find the file I'm giving it on a plate?

By : user2948206
Date : November 14 2020, 04:48 PM
it helps some times I have a problem with BASH script - a bit more complex problem that it seems to be. , I was mislead by the output from Jenkins, especially the line saying:
code :
00:00:44.709 bvt/engine/berichte_vergleichs_test.sh: line 218: somefile1-test.txt: File or directory not found
while read -r DATA1 ; do

    FILEPATH=$(find . -name "$DATA1-test.txt")

        while read -r CONFIG ; do

            #Doing something here

        done < "$FILEPATH"

        while read -r CONFIG ; do

            #Doing something here

        done < "$FILEPATH"

done < $DATAFILE
while read -r DATA1 ; do

    FILEPATH=$(find . -name "$DATA1-test.txt")

        while read -r CONFIG ; do

            #Doing something here

        done < $DATA1-test.txt 
        while read -r CONFIG ; do

            #Doing something here

        done < "$FILEPATH"

done < $DATAFILE


Share : facebook icon twitter icon
Whats wrong with this PHP While loop script

Whats wrong with this PHP While loop script


By : ziober
Date : March 29 2020, 07:55 AM
I wish did fix the issue. So It seems I was checking that $rand2 wasn't in the $newNumbers array in the first IF statement, which after the first loop of $i, $rand2 would be in $newNumbers every time as it won't get regenerated , hence the infinite loop.
Also thanks everyone for spotting the parse error with the extra quotes, I had it correct in TextWrangler (which is epic by the way), but made an error when simplifying the query for posting.
code :
$query = "INSERT INTO 'table' ('num_id', `num1`, `num2`) VALUES";

$i = 0;
while ($i <= 10){

    $rand = mt_rand(1000000000, 9999999999);
    if (!in_array($rand, $codes) && !in_array($rand, $newNumbers) ){
        $newNumbers[] = $rand;

        $second = 0;
        while ($second == 0){
            $rand2 = mt_rand(1000000000, 9999999999);
            if (!in_array($rand2, $codes) && !in_array($rand2, $newNumbers) ){
                $query .= " ('', $rand, $rand2)";
                $newNumbers[] = $rand2;
                $second = 1;

                $i++;
            }else
                $duplicates ++;
        }//end second loop



    }else
        $duplicates ++;
}//while
whats wrong in my code its giving parse error

whats wrong in my code its giving parse error


By : Joyce Yan
Date : March 29 2020, 07:55 AM
will help you You need to remove } from the last becaues that is extra.
so final line will be.
code :
} else {
      # For testing purposes, if there was an error, let's kill the script
      die("There was an error.");
 }
<?php
    require_once 'config/functions.php';
    session_start();
    $user=$_SESSION['google_data'];

    if(!empty($user))
    {
        $email = $user['email'];
        $fname = $user['given_name'];
        $lname = $user['family_name'];
        $gender=$user['gender'];
        $dob = $user['birthday'];
        $location = '';
        $picture = $user['picture'];
        $uid = $user['id'];
        $ousername = '';
        $link = $user['link'];
        $provider = 'google';
        $verified = $user['verified_email'];

        $gen=0;
        if($gender == 'male'){$gen=1;} else{$gen=0;}

        $new_dob = date( "Y-m-d H:i:s", strtotime($dob) );

        $userObj = new User();
        $userdata = $userObj->checkUser($email,$fname,$lname,$gen,$new_dob,$location,$picture,$uid,$ousername,$link,$provider,$new_verified); 

        if(!empty($userdata))
        {
            $_SESSION['id'] = $userdata['user_id'];
            $_SESSION['oauth_id'] = $userdata['user_oauth_id'];
            $_SESSION['username'] = $userdata['user_oauth_username'];
            $_SESSION['picture'] = $userdata['picture'];            
            $_SESSION['link'] = $userdata['link'];
            $_SESSION['fname'] = $userdata['user_fname'];
            $_SESSION['lname'] = $userdata['user_lname'];
            $_SESSION['gender'] = $userdata['user_gender'];
            $_SESSION['email'] = $userdata['user_email'];
            $_SESSION['oauth_provider'] = $userdata['user_oauth_provider'];             
            $_SESSION['oauth_id'] = $uid;

        }
    }
    else
    {
        die("There was an error.");
    }
?>
Whats wrong with my code? It's giving exception

Whats wrong with my code? It's giving exception


By : Jagmohan Farswan
Date : March 29 2020, 07:55 AM
hop of those help? I have written this code as I want to print 5 lowest numbers in a row out of 7 numbers, but don't want to print duplicate values. Now its giving some exception. , This
code :
last++;
index[last]=i;
index[last++]=i;
Have two CREATE TABLE statements and the second one keeps giving me a syntax error not sure whats wrong

Have two CREATE TABLE statements and the second one keeps giving me a syntax error not sure whats wrong


By : Pedriiiito
Date : March 29 2020, 07:55 AM
wish of those help Order is a reserved word in SQL (used for sorting) therefore, you'll need to surround it with backquotes to use it as a literal, e.g.:
code :
CREATE TABLE `Order` (orderID INT PRIMARY KEY);
counting characters in a file i cant find whats wrong

counting characters in a file i cant find whats wrong


By : Ville Toivianen
Date : March 29 2020, 07:55 AM
I hope this helps you . Your approach for reading the file contents is quite inefficient but should work, unless the stream pointer p has an invalid value such as NULL.
The classic code for this purpose is this:
code :
#include <stdio.h>

void countchars(FILE *fp) {
    int ch;
    int countc = 0;
    while ((c = getc(fp)) != EOF)
        countc++;
    printf("%d\n", countc);
}
#include <ctype.h>
#include <stdio.h>

void countwords(FILE *fp) {
    int countw = 0;
    int c, lastc = '\n';

    while ((c = getc(fp)) != EOF) {
        countw += isspace(lastc) && !isspace(c);
        lastc = c;
    }
    printf("%d\n", countw);
}
void countwords(FILE *fp) {
    int countw = 0;
    char c, lastc = '\n';

    while (fscanf(fp, "%c", &c) == 1) {
        countw += isspace((unsigned char)lastc) && !isspace((unsigned char)c);
        lastc = c;
    }
    printf("%d\n", countw);
}
Related Posts Related Posts :
  • how to replace a string at a specific position in a csv file using bash
  • how to delete duplicate lines in a text file in unix bash?
  • Compare a variables in bash
  • How do I use sed on a string?
  • Using bash variables for range in sed
  • convert a DURATION HH:MM:SS to seconds in bash
  • Shell make system paths click-able when printed out by my shell script
  • I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements
  • AWK between 2 patterns - first occurence
  • Nginx on docker - daemonize and attach to bash
  • Delete or Replace nth line in a file after a pattern match using shell scripts
  • Actual return code for SCP
  • How to exit a bash function that expects a return
  • Bash script to split file into two files while changing output file during processing
  • Pass command line arguments via sbatch
  • variable substitution (what do you call/name this method)?
  • Call function from another shell script
  • How to Grep and Replace With Exclusions
  • shell command to remove characters after a special character in bash/shell
  • How do I run a script for 1st working day of every month in cron?
  • Bash Unexpected End of File Error After Installing RVM
  • Nested Loop with increment on inner loop?
  • video orientation detection in bash
  • Interrupt sleep in bash with a signal trap
  • Want file rename script to add number at end with fixed length
  • What's the DRYest way to replace a file with a symlink in bash
  • How to run Bitcoin's autogen.sh file?
  • Renaming files in folder and subfolders using a list- Bash Script/Unix
  • Bash command to compare more than two files
  • If It is a directory append text
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org