I would like to make my own program but I have no idea how.. for example I want to make a typical 'Hello $user' program.
├── hi │ ├── hi.sh │ ├── hi_to.sh
#!/bin/bash ~/hi/hi_to.sh $1
#!/usr/bin/php <?php echo "\nHellO ".$argv."\n"; ?>
Run it in terminal:
me:~/hi → ./hi.sh User HellO User
and my question is: how to compile all this files into one bash program?
Cannot press QPushButton in a simple program
1:Shared objects (.so) static linking and opening other shared object, is the static library code shared between them?
You don't. JBoss 4.0.5 startup takes 15 minutes deploying a single war fileIf you want it in one script then you put it in one script in the first place.. Why the creators of Windows and Linux systems chose different ways to support Unicode?ubuntu: sem_timedwait not waking (C)linux dot utility (with xhprof)
2:Do I need JDK or only JRE?
I don't think i understand the question, for the reason this you could just call hi_to.sh like this:. Methods of sending web-generated config files to servers and restarting services
And it would run like you want, receive ting rid of the first sh script..
- Make sure the shebang line points to the correct php executable
- You don't have to call the script hi.php, just call it
- Make your script file executable ( e.g. via
chmod u+x path/to/hior
chmod a+rx path/to/hi, see http://en.wikipedia.org/wiki/Chmod)
- Make sure the file is within the search PATH for the user/accounts this are supposed to use your script (without typing the complete path)
The only way I could see this 'combined' is by using a here-doc, which basically causes the first script to generate the second, then execute it:.
In this example,
#!/bin/sh cat << EOF > /tmp/$$.php <?php \$string="$1"; echo "\nHellO ". \$string ."\n"; ?> EOF /usr/bin/php -q /tmp/$$.php retval=$? rm /tmp/$$.php exit $retval
$1will expand to the first argument. I have escaped the another variables (this are related only to PHP), which PHP will expand when it runs.
$$in a shell script just expands to the PID of the script, the actual temporary file is going to be any thing like
mktemp(1)is a enough safer way to make a temporary file name this is more resistant to link attacks and collisions.. It also saves the exit status of PHP in
retval, which is then returned when the script exits.. The resulting file will look like this (assuming the first argument to the shell script is
This is kind of an icky demonstration for how to use bash to write another scripts, although at least demonstrates this its possible. Its the only way I could think of to 'combine' (as you indicated) the two scripts this you posted..
<?php $string="foo"; echo "\nHello " . $string . "\n"; ?>