Get Parameter with Shell request


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get Parameter with Shell request
# 1  
Old 07-24-2015
Get Parameter with Shell request

How can I get Parameters with Shell Request.
I mean so but not work:
PHP:
Code:
error_reporting(E_ALL);

$hallo ="Hallo Welt";
print_r(shell_exec("sh client.sh $hallo"));

Shell:
Code:
echo $hallo
echo ceck


Last edited by rbatte1; 07-24-2015 at 12:26 PM..
# 2  
Old 07-24-2015
Why doesn't it work? The PHP is OK. It runs client.sh with a couple parameters. If the problem is with client.sh then you'll need to paste that rather than the PHP code.
# 3  
Old 07-24-2015
I have post the Shell script:


Its only:
Code:
 echo $hallo
echo ceck  
It display only ceck not "Hallo Welt"


Did i frorgot something?


I mean echo and the Variable $hallo display that.

Last edited by rbatte1; 07-24-2015 at 12:27 PM..
# 4  
Old 07-24-2015
Is the client.sh really a 'sh' or is it 'bash'?
Check the shebang of the file:
Code:
head -n1 client.sh

hth
# 5  
Old 07-25-2015
You should have received an empty line and then "ceck". Your $hallo variable will be undefined in the subshell as you did not export it.

---------- Post updated at 14:28 ---------- Previous update was at 14:26 ----------

If you called the script with $hallo as the first positional parameter, you'd need to echo $1 instead of $hallo.
# 6  
Old 07-26-2015
You parent process call subprocess
Code:
sh client.sh $hallo

On the shell subprocess you can handle arguments using variable 1, 2, 3 ...

So your subprocess script should be something like:
Code:
echo "arg1: $1"
echo "arg2: $2"
echo "argall: $*"
echo "argcnt: $#"
echo "myname: $0"

But command line is parsed using IFS = white space, so if your variable hallo include whitespaces, shell will split your value. If you like to keep whitespaces in your value, then you need to tell it: round the string using ' characters, you'll tell that "this is the string".

So your php include it:
Code:
<?php
$hallo ="Hallo Welt";
print_r(shell_exec("sh client.sh '$hallo'  "));
?>

It's also little risk to use sh. I'll tell exactly which shell I like to use: bash, ksh, dash, ... Usually sh is linked to the one of those, but on the older *nix it'll be Bourne Shell.

Example "I like to use bash to run my script":
Code:
<?php
$hallo ="Hallo Welt";
print_r(shell_exec("bash client.sh '$hallo'"));
?>

Or you can setup in your script (=correct method) which shell it need/has tested to use

Code:
#!/bin/ksh
echo hello world

And you setup execution privilege for script:
Code:
chmod a+rx client.sh

Then your php call "program", not script:
Code:
<?php
$hallo ="Hallo Welt";
print_r(shell_exec("client.sh '$hallo'"));
?>

And shell script will use that interpreter which you have set in the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing a command shell parameter to another shell

Good afternoon, i need your help pls I want to write a new script that start running as soon as a previus one finish via Autosys (it should be implemented via Autosys too to validate the exsitance and the successful transfered file to a remote server Whenever the file arrives to the path... (2 Replies)
Discussion started by: alexcol
2 Replies

2. Shell Programming and Scripting

Shell program request to download .pdf files

Hello, Would you suggest me a shell program that would launch the given url and if there is login we have enter the credentials. If the credentials are correct it would be redirected to home page of that url, the program will check if there are any PDF'S found automatically the PDF'S have... (5 Replies)
Discussion started by: pandu19
5 Replies

3. Shell Programming and Scripting

Shell program request

Hello, I'm requesting the shell program to compare 2 .csv files which will have large data. Can any one help me with this linux shell program Thanks in advance. Thanks and regards Ramanjaneya. K (1 Reply)
Discussion started by: pandu19
1 Replies

4. UNIX for Dummies Questions & Answers

Script shell calculate mean arrival request duration

hello, I have implemented this command : tshark -eth0 -T fiels -e frame.time et sip.Request-Line -z sip,stat > test2.txt the result of this command : test.txt: Aug 27, 2013 23:06:47.334270000 INVITE Aug 27, 2013 23:06:47.335045000 SIP/2.0 401 Unauthorized Aug 27, 2013... (1 Reply)
Discussion started by: Amouna
1 Replies

5. Shell Programming and Scripting

Request to check run php in Unix shell

Hi I m running a php file in Unix shell it says php cpmmnad not found bash-3.2$ cat echo.php <? php echo"heelo world" >? bash-3.2$ php echo.php bash: php: command not found actually I want to change certain thing a in a website using php script so I m beginner and trying... (6 Replies)
Discussion started by: manigrover
6 Replies

6. Shell Programming and Scripting

Shell script request

I've a master file which will contain 100 file names, The script should read file name from a master file and format the file as below in AIX. input file Filename This is a test file Output File Filename|This is a test file Thanks in advance for file in $FileList; do (5 Replies)
Discussion started by: udayakumar
5 Replies

7. Shell Programming and Scripting

Calling a request set from Unix shell Script

Hi All, I want to call a concurrent request set from a shell script. I am getting the syntax error "syntax error at line 417 : `(' unexpected" in the below script. v_request_id=fnd_request.submit_request(application => 'APPL_SHORT_NAME' ,program => 'PROGRAM_SHORT_NAME' ... (4 Replies)
Discussion started by: swatipevekar
4 Replies

8. Shell Programming and Scripting

simple shell - how to get a parameter typed in a shell script

Hi, I am new to unix and using linux 7.2. I would like to create a script that would make it easyer for me to run my java programms. At the moment I have to type java myJavaprogram I am trying to write a script that will allow me to type something like this "myscript myJavaprogram" or maybe... (4 Replies)
Discussion started by: cmitulescu
4 Replies

9. Shell Programming and Scripting

Shell program to accept multiple request at the same time

Hi, I got a script which sends the Email to the user based on certain variables received from Tivoli Server Monitoring 6.1. Now to keep track of the mails I have wrote a stored procedure in DB2 as we use DB2 UDB as back end which take the variables that were used to send the mail and store it... (3 Replies)
Discussion started by: tcskurra
3 Replies
Login or Register to Ask a Question