{"id":21046983,"url":"https://github.com/poweruser64/posix-arrays","last_synced_at":"2026-04-21T21:32:38.833Z","repository":{"id":139098231,"uuid":"555014553","full_name":"PowerUser64/posix-arrays","owner":"PowerUser64","description":"Array library for shell script, compatible with any POSIX-complient shell","archived":false,"fork":false,"pushed_at":"2022-10-24T03:56:33.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"trunk","last_synced_at":"2025-03-06T04:50:02.824Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PowerUser64.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-20T19:56:08.000Z","updated_at":"2023-07-08T23:34:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"0968ecba-7720-4f7b-9424-a0bed1e973c8","html_url":"https://github.com/PowerUser64/posix-arrays","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerUser64%2Fposix-arrays","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerUser64%2Fposix-arrays/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerUser64%2Fposix-arrays/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PowerUser64%2Fposix-arrays/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PowerUser64","download_url":"https://codeload.github.com/PowerUser64/posix-arrays/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243491118,"owners_count":20299253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T14:34:42.490Z","updated_at":"2025-12-29T21:18:10.458Z","avatar_url":"https://github.com/PowerUser64.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# POSIX Arrays\n\nDitch colon-separated lists and start using real arrays to store and access\ndata in your shell scripts!\n\nPOSIX shell script is awesome, but it has a small problem that keeps many\npeople using `bash`: no arrays! Well, not any more! This project lets you\neasily create, access, and iterate through arrays, with no limitations on what\ncharacters are allowed to be used, no character escaping required. If you can\nstore it in an environment variable, you can store it in a POSIX array.\n\n## Usage\n\nGeneral usage is to just source `posix-arrays.sh` in your script, However, you\ncan also use this library by downloading it on the fly with `curl` or by\ncopy/pasting it into your script.\n\n## Examples\n\nThese examples are all written assuming that you have initialized the array\nwith the code in the first example. If you want, try running these examples in\na strictly POSIX-complaint shell (for example, `bash --posix`).\n\nNote: arrays are zero-indexed and array names cannot have spaces\n\n- Create an array called `my_awesome_array` and put some data into it\n\n```bash\narray_init my_awesome_array ':' \"'\" '\"' '$USER' \"$USER\"\n```\n\n- Print the data from the array\n\n```bash\neval \"printf '%s\\n' $(array_print_esc my_awesome_array)\"\n```\n\n- Iterate through the array\n\n```bash\nwhile array_itr_next my_awesome_array; do\n   i=$((i+1))\n   array_set_here $i\n   printf '%s ' \"$(array_get_here my_awesome_array)\"\ndone \u0026\u0026 printf '\\n'\n```\n\nFor more usage, check [the documentation](./DOC.md).\n\n### 2D arrays\n\nDimensional arrays are also possible with this library. Check\n[`./tests.sh`](./tests.sh) for an example of how to create, access, and iterate\nthrough a 2D array. Do note that adding dimensions to your array will increase\nthe access time of the array. Only use this technique if there isn't another\nway to do what you're trying to do and you don't need lightening fast\nperformance. If you're okay with slower access times, this technique should\nwork well for most applications.\n\n## How does this work?\n\nThe basic idea is the fact we can use the `eval` keyword to write code with\ncode. What inspired this was realizing that the `eval` keyword could be used to\ndeclare a variable with a custom name, like this:\n\n```bash\nmy_var=hello\neval \"$my_var=world\"\necho $hello\n# prints \"world\"\n```\n\nThis library uses this ability to create variables with names like\n`my_awesome_array_0` to store the data at index 0 and `my_awesome_array_size`\nto store the array's size. In a broad sense, this library is abstraction of\nthis idea.\n\n## Contributing\n\nFirst off, thank you for taking the time to contribute! Contributions are more\nthan welcome, and there is even a top-secret commented out TODO list below this\nparagraph if you're looking for something to do. Otherwise, if you want to\ncontribute a bug fix, feel free to patch and submit a pull request with your\nchanges. If you want to contribute a feature, do note that this project is\nintended to stay somewhat simple, and all of the base functionality has been\nimplemented. If you come up with a feature you think is missing or would fit\nwell here, please open an issue to ask about it so I can provide feedback\nbefore you go through the work of implementing it.\n\nYou can test your changes with the tests in `./tests.sh`. If you add a feature,\nplease add a test for it.\n\n\u003c!--\n## TODO\n\n1. Make a dependency graph so users can find out what functions they\n   specifically need if they don't want to include the whole project.\n2. Maybe make a dimensional array library at some point.\n\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoweruser64%2Fposix-arrays","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoweruser64%2Fposix-arrays","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoweruser64%2Fposix-arrays/lists"}