{"id":28155956,"url":"https://github.com/ngpepin/safex","last_synced_at":"2026-05-09T03:31:22.334Z","repository":{"id":226325457,"uuid":"756046511","full_name":"ngpepin/safex","owner":"ngpepin","description":"Safex provides a safe way to do the equivalent of bash parameter expansion without the risk of undesired interpretation by the shell of string contents.  Safex allows literals to be injected into literals, avoiding the need for double quoting. This eliminates toil associated with escaping and taking other convoluted precautions just to get WYSIWYG","archived":false,"fork":false,"pushed_at":"2024-03-07T04:29:47.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T21:09:53.859Z","etag":null,"topics":["bash","expansion","programming-languages","shell","side-effects","substitution"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ngpepin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-02-11T20:25:13.000Z","updated_at":"2024-03-07T00:40:32.000Z","dependencies_parsed_at":"2024-03-09T03:01:21.193Z","dependency_job_id":null,"html_url":"https://github.com/ngpepin/safex","commit_stats":null,"previous_names":["ngpepin/safex"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ngpepin/safex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngpepin%2Fsafex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngpepin%2Fsafex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngpepin%2Fsafex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngpepin%2Fsafex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngpepin","download_url":"https://codeload.github.com/ngpepin/safex/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngpepin%2Fsafex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001051,"owners_count":26082991,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bash","expansion","programming-languages","shell","side-effects","substitution"],"created_at":"2025-05-15T07:14:55.499Z","updated_at":"2025-10-09T08:32:55.450Z","avatar_url":"https://github.com/ngpepin.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Safex Usage Guide\n\nSafex provides a safe way to do the equivalent of bash parameter expansion without the risk of undesired interpretation by the shell of string contents.\n\n## Features\n\n- Safex allows literals to be injected into literals, avoiding the need for double quoting. This reduces the need to escape and take other convoluted precautions in order to protect text from interference by the shell. \"Safe\" in this context means 'safe from interpretation' by the shell causing wayward expansions, variable and command substitutions, globbing, brace expansions, tilde expansions, case modification, etc.\n\n- It makes string manipulation and parameter passing more similar to the dominant paradigm used in programming languages, following the familiar pattern:\n  \n  `\u003cTemplate with Embedded Arguments Placeholders {1} {2} {3}\u003e`, \n  `\u003cValue of Argument {1}\u003e`, \n  `\u003cValue of {2}\u003e`, \n  `\u003cValue of {3}\u003e`... \n\n  This pattern is seen in C#'s `Console.WriteLine` and is common to many programming languages.\n\n- Safex can be used to rearrange the order of parameters to allow more frequent use of bash aliases, especially when expressions require that the text or parameters provided after an alias (i.e., `myalias \u003cmyarg\u003e \u003cmytext\u003e`) be located somewhere else than at the very end of the line.\n\n- Note that more recent versions of Safex can return an `eval` command string that is executed by a bash wrapper function within a bash script. This is quite powerful, though clearly not at all 'safe'! Much of the documentation herein needs to be updated to reflect this change, which should be controlled by a command line switch to make the behaviour optional.\n\n## Usage\n\n```bash\nsafex templateString value1 [value2...]\n```\n\n## Examples\n\n**Example with two parameters and special characters:**\n\n```bash\noutput=$(./safex $'My dog\\'s name is {0} and my cat\\'s name is {1}' 'Fido' 'Whiskers')\neval \"$output\"\n```\n\n**Example with three parameters, special characters, and the need for complex escaping:**\n\n```bash\noutput=$(./safex $'Here are the names: {0}, {1}, and {2}' 'Fido' 'Whiskers' 'Tweety')\neval \"$output\"` \n```\n\n**Example using variables:**\n\n```bash \noutput=$(./safex \"$template\" \"$param1\" \"$param2\")\neval \"$output\"` \n```\n\n**To execute the returned string (not necessary since recent changes):**\n\n```bash\nlocal temp_file=$(mktemp)\n/usr/bin/safex \"${args[@]}\" \u003e \"$temp_file\"\necho -en \"executing: \"; cat \"$temp_file\"; echo\nsudo /usr/bin/unbuffer bash -c 'USER=root; ' \"$(cat \"$temp_file\")\" | more` \n```\n\n## License\n\nThe code in this project is licensed under the MIT License. This means you can freely use, modify, distribute, and sell it under the same license.\n\n```markdown\nMIT License\n\nCopyright (c) [year] [full name of copyright owner]\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n\n## Disclaimer and Limitation of Liability\n\n```markdown\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, COPYRIGHT HOLDERS, OR PROJECT CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS RELATED TO THE SOFTWARE.\n\nUSE OF THE SOFTWARE IS AT YOUR OWN RISK. PLEASE REVIEW THE LICENSE AND THE SOFTWARE'S DOCUMENTATION BEFORE USING THE SOFTWARE. THE AUTHORS AND CONTRIBUTORS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. \nNote: Replace [year] with the current year and [full name of copyright owner] with the name of the copyright holder (which might be your name or your organization's name). This text ensures users are aware of their rights under the MIT License, and the disclaimer provides a basic waiver of liability, common in open source projects.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngpepin%2Fsafex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngpepin%2Fsafex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngpepin%2Fsafex/lists"}