shell script - to not change working directory to that of the script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    shell script - to not change working directory to that of the script


    Hi,

    I'm running a PHP script from a shell (bash, ...) - not from a web
    server.

    So I use a script of the form:

    #!/usr/bin/php
    <?php
    var_dump($argv) ;
    ?>

    and then I can run the script directly, rather than:
    [user]# php -f script_name

    Running the script this way changes the current directory to that of
    the script.

    I don't want this behaviour - I want the current directory to be from
    where I run the script, so I can write the PHP code to work on 'local'
    files (./*) - just like it should for CLI SAPI interface.

    I can't use the -C option (PHP throws an error) like:

    #!/usr/bin/php -q -C

    Anyone know how to do what I want ?

    System: Linux Fedora Core 1, PHP Version 4.3.8

    Thanks,
    John.

  • Gert

    #2
    Re: shell script - to not change working directory to that of the script

    > I don't want this behaviour - I want the current directory to be from[color=blue]
    > where I run the script, so I can write the PHP code to work on 'local'
    > files (./*) - just like it should for CLI SAPI interface.[/color]

    John,

    Can't you simply give your script a parameter of the needed working
    directory and then
    use the chdir()-command to change the script's current directory?

    regards,

    Gert.


    Comment

    Working...