PHPackages                             alexskrypnyk/shell-variables-extractor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alexskrypnyk/shell-variables-extractor

Abandoned → [alexskrypnyk/shellvar](/?search=alexskrypnyk%2Fshellvar)Library[Utility &amp; Helpers](/categories/utility)

alexskrypnyk/shell-variables-extractor
======================================

Utility to work with shell variables.

1.7.0(1mo ago)26601[1 issues](https://github.com/AlexSkrypnyk/shellvar/issues)GPL-2.0-or-laterPHPPHP &gt;=8.2CI passing

Since Mar 21Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/AlexSkrypnyk/shellvar)[ Packagist](https://packagist.org/packages/alexskrypnyk/shell-variables-extractor)[ Docs](https://github.com/AlexSkrypnyk/shellvar)[ Patreon](https://www.patreon.com/alexskrypnyk)[ RSS](/packages/alexskrypnyk-shell-variables-extractor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (22)Used By (0)

  ![Shellvar logo](https://camo.githubusercontent.com/12c9e94d2440a96ed25d8d886deffc1c9e0ff298153d79f499e0585fa95385d1/68747470733a2f2f706c616365686f6c642e6a702f3030303030302f6666666666662f323030783230302e706e673f746578743d5368656c6c766172266373733d253742253232626f726465722d7261646975732532322533412532322532303130307078253232253744)

Utility to work with shell variables
====================================

[](#utility-to-work-with-shell-variables)

[![GitHub Issues](https://camo.githubusercontent.com/4a8ab17d5852f90eb13f53636ac295e40774fe3ca4d271a7305629a0c4f308ef/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f416c6578536b7279706e796b2f7368656c6c7661722e737667)](https://github.com/AlexSkrypnyk/shellvar/issues)[![GitHub Pull Requests](https://camo.githubusercontent.com/7b2b70c7a728e9f64505682d2850871548a0d1277e2d56e64a210300aa1986e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f416c6578536b7279706e796b2f7368656c6c7661722e737667)](https://github.com/AlexSkrypnyk/shellvar/pulls)[![Test PHP](https://github.com/AlexSkrypnyk/shellvar/actions/workflows/test-php.yml/badge.svg)](https://github.com/AlexSkrypnyk/shellvar/actions/workflows/test-php.yml)[![codecov](https://camo.githubusercontent.com/3e29793d6235e7b45f113850ef02bb578f39e2f7ec8a04cee958845b6e3a8401/68747470733a2f2f636f6465636f762e696f2f67682f416c6578536b7279706e796b2f7368656c6c7661722f67726170682f62616467652e7376673f746f6b656e3d37574542314958425954)](https://codecov.io/gh/AlexSkrypnyk/shellvar)[![GitHub release (latest by date)](https://camo.githubusercontent.com/ff6e8bb5499ac5e89fcf8b0380c35c433c9225f436f7351ea6f4baba14c38e71/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f416c6578536b7279706e796b2f7368656c6c766172)](https://camo.githubusercontent.com/ff6e8bb5499ac5e89fcf8b0380c35c433c9225f436f7351ea6f4baba14c38e71/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f416c6578536b7279706e796b2f7368656c6c766172)[![LICENSE](https://camo.githubusercontent.com/fcf7053c07744c5aa7323d73cea7268ba398fd2a2361425178e55af36c68b66d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f416c6578536b7279706e796b2f7368656c6c766172)](https://camo.githubusercontent.com/fcf7053c07744c5aa7323d73cea7268ba398fd2a2361425178e55af36c68b66d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f416c6578536b7279706e796b2f7368656c6c766172)[![Renovate](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)](https://camo.githubusercontent.com/35389190ce58a3690fe850342c1c3fd4f54e4c10ba8996741c8558ee24bf50dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f72656e6f766174652d656e61626c65642d677265656e3f6c6f676f3d72656e6f76617465626f74)

[![Docker Pulls](https://camo.githubusercontent.com/4e860a0fe1636028ca541f87758d6ff962b7b8f9e412a09bfb61b17ce1617acf/68747470733a2f2f696d672e736869656c64732e696f2f646f636b65722f70756c6c732f647265766f70732f7368656c6c7661723f6c6f676f3d646f636b6572)](https://hub.docker.com/r/drevops/shellvar)[![amd64](https://camo.githubusercontent.com/d9302b8e56815ae616e055ec94f623253770190fdb9c2c9dbda2a24acb9325cb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617263682d6c696e7578253246616d6436342d627269676874677265656e)](https://camo.githubusercontent.com/d9302b8e56815ae616e055ec94f623253770190fdb9c2c9dbda2a24acb9325cb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f617263682d6c696e7578253246616d6436342d627269676874677265656e)

---

Features
--------

[](#features)

- Lint variables:
    - Report on shell variables that are not in `${VAR}` format.
    - Fix shell variables that are not in `${VAR}` format.
- Extract variables:
    - Scan a file or a directory containing shell scripts and extract found variables with comments and assigned values with [advanced interpolation support](tests/phpunit/Fixtures/test-data-real.sh).
    - Filter variables: exclude local, exclude by prefix, exclude from a list in file.
    - Format output as a *CSV*, *Markdown table* or *Markdown blocks* (defined in the template).
    - Extend filters and formatters with your own custom classes.

Installation
------------

[](#installation)

Download the latest version of the `shellvar` from the [releases page](https://github.com/AlexSkrypnyk/shellvar/releases)and run on host machine:

```
./shellvar [command] [options] path/to/script.sh
```

or run as a Docker container:

```
docker run -v $(pwd):/app drevops/shellvar [command] [options] path/to/script.sh
```

Usage - Lint
------------

[](#usage---lint)

- Report on shell variables that are not in `${VAR}` format.
- Fix shell variables that are not in `${VAR}` format.

### Lint file or directory

[](#lint-file-or-directory)

```
./shellvar lint path/to/script.sh

./shellvar lint path/to/dir

./shellvar lint --extension=sh --extension=bash --extension=bats path/to/dir
```

Example:

```
./shellvar lint tests/phpunit/Fixtures/unwrapped.sh

./shellvar lint tests/phpunit/Fixtures

./shellvar lint --extension=sh --extension=bash --extension=bats tests/phpunit/Fixtures
```

### Fix file or directory

[](#fix-file-or-directory)

```
./shellvar lint --fix path/to/script.sh

./shellvar lint --fix path/to/dir

./shellvar lint --fix --extension=sh --extension=bash --extension=bats path/to/dir
```

Example:

```
./shellvar lint --fix tests/phpunit/Fixtures/unwrapped.sh

./shellvar lint --fix tests/phpunit/Fixtures

./shellvar lint --fix --extension=sh --extension=bash --extension=bats tests/phpunit/Fixtures
```

Usage - Extract
---------------

[](#usage---extract)

By default, variable names, descriptions (taken from the comments) and their values are printed to STDOUT in the *CSV* format. You can also change the output format to *Markdown table* or *Markdown blocks*.

Given the following shell script ( see [extended example](tests/phpunit/Fixtures/test-data.sh) used in tests):

```
# Assignment to scalar value.
VAR1=val1
# Assignment to another variable.
VAR2="${VAR1}"
# Parameter expansion.
VAR3=${val3:-abc}
# Parameter expansion with a default value using
# another variable $VAR3.
#
# Continuation of the multi-line comment.
VAR4=${val4:-$VAR3}
```

### CSV (default)

[](#csv-default)

```
./shellvar extract path/to/script.sh
```

```
Name;"Default value";Description
VAR1;val1;"Assignment to scalar value."
VAR2;${VAR1};"Assignment to another variable."
VAR3;abc;"Parameter expansion."
VAR4;${VAR3};"Parameter expansion with a default value using another variable $VAR3.

Continuation of the multi-line comment."
```

### Markdown table

[](#markdown-table)

```
./shellvar extract --format=md-table path/to/script.sh
```

 Click to see output```
| Name   | Default value | Description                                                                                                                      |
|--------|---------------|----------------------------------------------------------------------------------------------------------------------------------|
| `VAR1` | `val1`        | Assignment to scalar value.                                                                                                      |
| `VAR2` | `${VAR1}`     | Assignment to another variable.                                                                                                  |
| `VAR3` | `abc`         | Parameter expansion.                                                                                                             |
| `VAR4` | `${VAR3}`     | Parameter expansion with a default value usinganother variable `$VAR3`.Continuation of the multi-line comment. |
```

which renders as

NameDefault valueDescription`VAR1``val1`Assignment to scalar value.`VAR2``${VAR1}`Assignment to another variable.`VAR3``abc`Parameter expansion.`VAR4``${VAR3}`Parameter expansion with a default value using
another variable `$VAR3`.

Continuation of the multi-line comment.### Markdown blocks

[](#markdown-blocks)

```
./shellvar extract --format=md-blocks path/to/script.sh
```

 Click to see output```
### `VAR1`

Assignment to scalar value.

Default value: `val1`

### `VAR2`

Assignment to another variable.

Default value: `${VAR1}`

### `VAR3`

Parameter expansion.

Default value: `abc`

### `VAR4`

Parameter expansion with a default value usinganother variable `$VAR3`.

Continuation of the multi-line comment.

Default value: `${VAR3}`
```

which renders as

### `VAR1`

[](#var1)

Assignment to scalar value.

Default value: `val1`

### `VAR2`

[](#var2)

Assignment to another variable.

Default value: `${VAR1}`

### `VAR3`

[](#var3)

Parameter expansion.

Default value: `abc`

### `VAR4`

[](#var4)

Parameter expansion with a default value using
another variable `$VAR3`.

Continuation of the multi-line comment.

Default value: `${VAR3}`

#### Advanced: Markdown blocks with links and custom template

[](#advanced-markdown-blocks-with-links-and-custom-template)

```
./shellvar extract --format=md-blocks --md-link-vars --md-block-template-file=path/to/template.md path/to/script.sh
```

 Click to see output```
### `VAR1`

Assignment to scalar value.

Default value: `val1`

Path: `1.sh`

Paths: `1.sh`

### `VAR2`

Assignment to another variable.

Default value: `${VAR1}`

Path: `1.sh`

Paths: `1.sh`

### `VAR3`

Parameter expansion.

Default value: `abc`

Path: `1.sh`

Paths: `1.sh`

### `VAR4`

Parameter expansion with a default value usinganother
variable [`$VAR3`](#VAR3).

Continuation of the multi-line comment.

Default value: `${VAR3}`

Path: `1.sh`

Paths: `1.sh`
```

which renders as

### `VAR1`

[](#var1-1)

Assignment to scalar value.

Default value: `val1`

Path: `1.sh`

Paths: `1.sh`

### `VAR2`

[](#var2-1)

Assignment to another variable.

Default value: `${VAR1}`

Path: `1.sh`

Paths: `1.sh`

### `VAR3`

[](#var3-1)

Parameter expansion.

Default value: `abc`

Path: `1.sh`

Paths: `1.sh`

### `VAR4`

[](#var4-1)

Parameter expansion with a default value using
another variable [`$VAR3`](#VAR3).

Continuation of the multi-line comment.

Default value: `${VAR3}`

Path: `1.sh`

Paths: `1.sh`

### Column manipulation

[](#column-manipulation)

Control the order and visibility of columns in tabular output formats (CSV and Markdown table).

#### Reorder columns

[](#reorder-columns)

```
./shellvar extract --format=csv --column-order="Description,Name" path/to/script.sh
```

This will output columns in the order: Description, Name, Default value (unspecified columns are appended).

#### Show only specific columns

[](#show-only-specific-columns)

```
./shellvar extract --format=md-table --only-columns="Name,Description" path/to/script.sh
```

This will output only the Name and Description columns.

#### Exclude columns

[](#exclude-columns)

```
./shellvar extract --format=csv --exclude-columns="Default value" path/to/script.sh
```

This will output all columns except "Default value".

#### Combine column options

[](#combine-column-options)

```
./shellvar extract --format=csv --only-columns="Name,Description,Default value" --column-order="Description,Name" path/to/script.sh
```

This will first filter to only the specified columns, then reorder them.

### Options

[](#options)

There are options for different phases: extraction, filtering and formatting.

"Multiple values allowed" means that you can specify the option multiple times like so: `--exclude-prefix=VAR1 --exclude-prefix=VAR2` etc.

#### Extraction

[](#extraction)

NameDescriptionDefault value`paths`File or directory to scan. Multiple files separated by space.`--skip-text=SKIP`Skip variable extraction if the comment has this specified text.`@skip``--skip-description-prefix=PREFIX`Skip description lines that start with the provided prefix. Multiple values allowed.#### Filtering

[](#filtering)

NameDescriptionDefault value`--exclude-local`Remove local variables.`--exclude-prefix=PREFIX`Exclude variables that start with the provided prefix. Multiple values allowed`--exclude-from-file=FILE`A path to a file that contains variables to be excluded from the extraction process. Multiple values allowed.#### Format

[](#format)

NameDescriptionDefault value`--format=FORMAT`The output format: CSV (`csv`), Markdown table (`md-table`), Markdown blocks (`md-blocks`).`csv``--sort`Sort variables in ascending order by name.`--unset`A string to represent a value for variables that are defined but have no set value.`UNSET``--fields=FIELDS`Semicolon-separated list of fields. Each field is a key-label pair in the format "key=label". If label is omitted, key is used as label.`name=Name;default_value="Default value;description=Description``--path-strip-prefix=PREFIX`Strip the provided prefix from the path.`--csv-separator=SEPARATOR`Separator for the CSV output format.`;``--column-order=COLUMNS`Comma-separated list of column names to specify output order. Columns not specified are appended in their original order. Only applies to tabular formats (csv, md-table).`--only-columns=COLUMNS`Comma-separated list of column names to include. Only these columns will appear in output. Only applies to tabular formats (csv, md-table).`--exclude-columns=COLUMNS`Comma-separated list of column names to exclude from output. Only applies to tabular formats (csv, md-table).`--md-link-vars`Link variables within usages to their definitions in the Markdown output format.`--md-link-vars-anchor-case`The case of the anchors when linking variables. Can be one of "preserve", "lower" or "upper".`preserve``--md-no-inline-code-wrap-vars`Do not wrap variables to show them as inline code in the Markdown output format.`--md-no-inline-code-wrap-numbers`Do not wrap numbers to show them as inline code in the Markdown output format.`--md-inline-code-extra-file=FILE`A path to a file that contains additional strings to be formatted as inline code in the Markdown output format. Multiple values allowed.`--md-block-template-file=FILE`A path to a Markdown template file used for Markdown blocks (md-blocks) output format. `{{ name }}`, `{{ description }}`, `{{ default_value }}` and `{{ path }}` tokens can be used within the template.Maintenance
-----------

[](#maintenance)

```
composer install
composer lint
composer lint:fix
composer test
composer build

```

### Docker publishing

[](#docker-publishing)

Shellvar is [published as a Docker image](https://hub.docker.com/r/drevops/shellvar) with the following tags:

- `XX.YY.ZZ` tag - when release tag is published on GitHub.
- `latest` - when release tag is published on GitHub.
- `canary` - on every push to `main` branch

---

*This repository was created using the [Scaffold](https://getscaffold.dev/) project template*

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance81

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 54.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Recently: every ~17 days

Total

18

Last Release

59d ago

Major Versions

0.7.0 → 1.0.02024-04-29

PHP version history (2 changes)0.5.0PHP &gt;=8.1

1.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b57b0fd0b96f77f2efa1a1889af0ae607fa139bcc1256e809ee3ebbb30907364?d=identicon)[alexdrevops](/maintainers/alexdrevops)

---

Top Contributors

[![AlexSkrypnyk](https://avatars.githubusercontent.com/u/378794?v=4)](https://github.com/AlexSkrypnyk "AlexSkrypnyk (109 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (81 commits)")[![tannguyen04](https://avatars.githubusercontent.com/u/2858879?v=4)](https://github.com/tannguyen04 "tannguyen04 (8 commits)")[![lankmiler](https://avatars.githubusercontent.com/u/10814550?v=4)](https://github.com/lankmiler "lankmiler (1 commits)")[![StevenWalker98](https://avatars.githubusercontent.com/u/262267976?v=4)](https://github.com/StevenWalker98 "StevenWalker98 (1 commits)")

---

Tags

bashextractorshellshell-scriptvariable

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alexskrypnyk-shell-variables-extractor/health.svg)

```
[![Health](https://phpackages.com/badges/alexskrypnyk-shell-variables-extractor/health.svg)](https://phpackages.com/packages/alexskrypnyk-shell-variables-extractor)
```

###  Alternatives

[php-soap/wsdl

Deals with WSDLs

173.5M12](/packages/php-soap-wsdl)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

4743.5k10](/packages/phel-lang-phel-lang)[symfony/ai-bundle

Integration bundle for Symfony AI components

30282.3k6](/packages/symfony-ai-bundle)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
