Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I am trying to pass arguments to a bash script and then to a php script, I have literally looked at 30+ links, and tried over a dozen examples, and I for whatever reason have not been able to get the following to work, I am seriously frustrated, any help is so very much appreciated.

For the sake of this question, lets say I have the following bash script (test.sh)

#!/usr/bin/env bash

/usr/bin/php test.php $@

and I have the following PHP script (test.php)

<?php

print_r($argv);

and I am trying to execute the bash script with the following arguments

./test.sh hello world "how are you"

the results of the above is the following

Array
(
    [0] => test.php
    [1] => hello
    [2] => world
    [3] => how
    [4] => are
    [5] => you
)

and I am looking for the results to be

Array
(
    [0] => test.php
    [1] => hello
    [2] => world
    [3] => how are you
)

Any ideas are greatly appreciated... I am banging my head against the desk....

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Would have been enough to have a look at the "QUOTING" block in bash's man page... (to find a pointer to the PARAMETERS block where it is explained)

/usr/bin/php test.php "$@"
share|improve this answer
    
hrmmmmm, ok, lol, let me rephrase the question, that absolutely worked in this example, however, in the actual php cli script, I am using it is not working... editing now –  Jeffrey L. Roberts Mar 7 '14 at 4:49
    
ooook, it looks like this is not a problem with the examples, or even the php, the root of this problem lies within github.com/jeffreyroberts/sub it appears... which is a heavily modified fork of github.com/37signals/sub ... Thank you all for your help, at least the problem has been identified, I wish I had just ran the damn example scripts lol.... when I wrap $@ in double quotes using the sub <sub-command> arg1 "arg2a arg2b", the php script was returning an array with 2 elements, the full script path, and all of the arguments, I will dig into sub and see whats up, thanks again! –  Jeffrey L. Roberts Mar 7 '14 at 5:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.