Results 1 to 6 of 6

Thread: Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

  1. #1
    Join Date
    Nov 2018
    Beans
    8

    Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

    I just began using c9 tried running following php code with runner PHP-CLI getting bash error

    running sample code :: https://docs.aws.amazon.com/cloud9/l...ample-php.html


    (standard_in) 1: syntax error
    bash: line 9: [: -eq: unary operator expected
    Kindly guide how to fix
    <?php
    print(‘Hello, World!’);
    print("\nThe sum of 2 and 3 is 5.");
    $sum = (int)$argv[1] + (int)$argv[2];
    print("\nThe sum of $argv[1] and $argv[2] is $sum.");
    ?>

    Last edited by wildmanne39; July 15th, 2019 at 06:00 AM. Reason: Normalized Fonts

  2. #2
    Join Date
    Dec 2014
    Beans
    2,566

    Re: Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

    You've got backticks instead of single quotes around the string "Hello, World". The backticks make php call the shell to execute whatever is between the backticks.

    Holger

  3. #3
    Join Date
    Nov 2018
    Beans
    8

    Re: Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

    I am trying to simply run the following code after removing hello world just to try as guided in https://docs.aws.amazon.com/cloud9/l...ample-php.html
    <?php

    print("\nThe sum of 2 and 3 is 5.");


    $sum = (int)$argv[1] + (int)$argv[2];


    print("\nThe sum of $argv[1] and $argv[2] is $sum.");
    ?>

    getting error

    Running PHP script home/ubuntu/environment/cloud_ide1/dev/hello.php (source location)
    (standard_in) 1: syntax error
    bash: line 9: [: -eq: unary operator expected
    Could not open input file: home/ubuntu/environment/cloud_ide1/dev/hello.php

  4. #4
    Join Date
    Dec 2014
    Beans
    2,566

    Re: Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

    Whatever is still wrong, it's not the PHP-Code. I copied your code into an editor, saved it as 'test.php' and ran it from the shell with 'php test.php 1 1' and got the expected results.
    From the errors you get I believe the IDE calls some shell-script to run your program and passes a lot of options to that script. Some wrong setting in the IDE is breaking the script.

    Holger

  5. #5
    Join Date
    Nov 2018
    Beans
    8

    Re: Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

    I restarted and passed arguments as shown here with filename.php 10 12, it shows perfect output but don;t know why it's shows syntax error above the output and -eq unary operator expected

    Code:
    ___
    <?php
      print("Hello, World!");
    
    
      print("\nThe sum of 2 and 3 is 5.");
    
    
      $sum = (int)$argv[1] + (int)$argv[2];
    
    
      print("\nThe sum of $argv[1] and $argv[2] is $sum.");
    ?>
    output
    _____
    Running PHP script /home/ubuntu/environment/cloud_ide1/dev/hello.php
    (standard_in) 1: syntax error
    bash: line 9: [: -eq: unary operator expected
    Hello, World!
    The sum of 2 and 3 is 5.
    The sum of 10 and 12 is 12.
    Last edited by aruneshdutta; July 15th, 2019 at 07:10 AM.

  6. #6
    Join Date
    Feb 2008
    Location
    Texas
    Beans
    29,807
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: Using AWS cloud9 linked to ubuntu Getting Bash error while running PHP

    Please use the default font color and properties unless you need to highlight or draw attention to a part of your post.

    Please use code tags - if you are using New Reply button - highlight text and use the # button in the text box header.

    If using Quick Reply then [code] at the beginning and [/code] at the end.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •