https://github.com/nazmulpcc/phpsh
Generate shell scripts from PHP with ease
https://github.com/nazmulpcc/phpsh
bash php shell-script
Last synced: 3 months ago
JSON representation
Generate shell scripts from PHP with ease
- Host: GitHub
- URL: https://github.com/nazmulpcc/phpsh
- Owner: nazmulpcc
- License: mit
- Created: 2020-06-15T15:35:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-13T14:42:35.000Z (about 3 years ago)
- Last Synced: 2025-03-23T23:13:56.349Z (4 months ago)
- Topics: bash, php, shell-script
- Language: PHP
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PhpSh
[](https://packagist.org/packages/nazmulpcc/phpsh)
[](https://github.com/nazmulpcc/phpsh/actions?query=workflow%3Arun-tests+branch%3Amaster)
[](https://packagist.org/packages/nazmulpcc/phpsh)
## InstallationYou can install the package via composer:
```bash
composer require nazmulpcc/phpsh
```## Why?
If writing shell scripts make you *uncomfortable* because it feels like an ecrypted alient language, PhpSh is for you.
## Examples
```php
use PhpSh\Condition;
use PhpSh\Script;$condition = Condition::create('$i')->lessThan(10);
(new Script())
->set('i', 0)
->while($condition, function (Script $script){
$script->echo('$i');
$script->increment('i');
})
->generate();
```
The above example code will generate shell executable script like this:
``` sh
i=0
while [ $i -lt 10 ]; do
echo -n $i
let i+=1
done
```
Don't know how to do "if a file exists and is writable then do something"? PhpSh got your back!
```php
$condition = Condition::create()
->fileExists('/path/to/file')
->and()
->writable('/path/to/file');(new Script())
->if($condition, function (Script $script){
$script->printf("File found\n");
})->else(function (Script $script){
$script->printf("Oops!\n");
})
->generate();
```
## Testing``` bash
composer test
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security
If you discover any security related issues, please email nazmulpcc [at] gmail.com instead of using the issue tracker.
## Credits
- [Nazmul Alam](https://github.com/nazmulpcc)
- [All Contributors](../../contributors)## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.