0

i'm learning the shell scripting using php

shell.sh

`#!/bin/bash

    BASEDIR=$(dirname $0)
    echo "BASE DIRECTOY $BASEDIR"           ## get base directory
    echo "PRESENT WORKING DIRECTORY $PWD"   ## get present working directory

    declare arr="`dir`"
    echo $arr

   for i in $arr
   do 
       echo $i
   done`

And i'm executing this shell script using php script

phpshell.php

`error_reporting(1);
    $output = shell_exec('sh shell.sh');
    echo $output;`

So when i'm echoing $arr in shell script, its working fine but when i applying for loop on same array in shell script, it's not printing file names

output

BASE DIRECTOY .
PRESENT WORKING DIRECTORY /cygdrive/c/wamp/www/shell
Copy\ of\ shell.sh htaccess new phpshell.php shell.sh

i tried all answers from stackoverflow and internet but no one solution is working. i'm running this code on wampserver and windows xp sp2. Also i installed a cygwin utility. i think there is no problem with cygwin

Any help would be greatly appreciated....

1 Answer 1

1

In phpshell.php, start by changing

$output = shell_exec('sh shell.sh');

to

$output = shell_exec('bash shell.sh');

The old Bourne shell (sh) doesn't understand 'declare'. I guess you got the error message

shell.sh: declare: not found

Another way to solve it is to remove declare from shell.sh.

(Your listings look a bit odd. Why do you frame all code with back-ticks?)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.