Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Probably need path to script
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

You are calling your bash script with sh. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

$cmd = "bash myscript.sh";

or, since you do have a #!/bin/bash shebang, and assuming the script has the executable bit set, just call it directly:

$cmd = "myscript"./myscript.sh";

You are calling your bash script with sh. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

$cmd = "bash myscript.sh";

or, since you do have a #!/bin/bash shebang, and assuming the script has the executable bit set, just call it directly:

$cmd = "myscript.sh";

You are calling your bash script with sh. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

$cmd = "bash myscript.sh";

or, since you do have a #!/bin/bash shebang, and assuming the script has the executable bit set, just call it directly:

$cmd = "./myscript.sh";
added 152 characters in body
Source Link
terdon
  • 252.6k
  • 69
  • 481
  • 719

You don't show how your PHP script callsare calling your shellbash script, but from what you describe it's a safe bet that it is calling it using the default with sh of your system. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

bash$cmd /path/to/your/script= "bash myscript.shsh";

or, since you do have a #!/bin/bash shebang, and assuming the script has the executable bit set, just call it directly:

$cmd = "myscript.sh";

You don't show how your PHP script calls your shell script, but from what you describe it's a safe bet that it is calling it using the default sh of your system. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

bash /path/to/your/script.sh

You are calling your bash script with sh. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

$cmd = "bash myscript.sh";

or, since you do have a #!/bin/bash shebang, and assuming the script has the executable bit set, just call it directly:

$cmd = "myscript.sh";
added 1 character in body
Source Link
terdon
  • 252.6k
  • 69
  • 481
  • 719

You don't show how your PHP script calls your shell script, but from what you describe it's a safe bet that it is calling it using the default sh of your system. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any speciaspecial features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

bash /path/to/your/script.sh

You don't show how your PHP script calls your shell script, but from what you describe it's a safe bet that it is calling it using the default sh of your system. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any specia features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

bash /path/to/your/script.sh

You don't show how your PHP script calls your shell script, but from what you describe it's a safe bet that it is calling it using the default sh of your system. This is usually a basic POSIX shell like dash. The [[ isn't POSIX, it's a bashism (also present in some other shells) so your sh doesn't support it:

$ dash -c "if [[ 10 -gt 8 ]]; then echo yeah; fi"
dash: 1: [[: not found

So, either change your script to use the standard [ (you're not using any special features of [[ anyway):

if [ -e /var/log/apache2/error.log ]; then
    echo YES
fi

Or change your PHP script and call the script with bash explicitly:

bash /path/to/your/script.sh
Source Link
terdon
  • 252.6k
  • 69
  • 481
  • 719
Loading