{"id":14156603,"url":"https://github.com/vaeth/push","last_synced_at":"2025-07-14T03:12:00.006Z","repository":{"id":3194930,"uuid":"4227932","full_name":"vaeth/push","owner":"vaeth","description":"A POSIX shell function to treat a variable like an array, quoting args.","archived":false,"fork":false,"pushed_at":"2021-06-13T11:16:22.000Z","size":20,"stargazers_count":36,"open_issues_count":1,"forks_count":3,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-30T05:04:41.885Z","etag":null,"topics":["posix","quotes","quoting-args","shell"],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/vaeth.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}},"created_at":"2012-05-04T18:41:32.000Z","updated_at":"2024-11-23T10:31:43.000Z","dependencies_parsed_at":"2022-09-10T22:10:24.183Z","dependency_job_id":null,"html_url":"https://github.com/vaeth/push","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/vaeth/push","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaeth%2Fpush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaeth%2Fpush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaeth%2Fpush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaeth%2Fpush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaeth","download_url":"https://codeload.github.com/vaeth/push/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaeth%2Fpush/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265237222,"owners_count":23732507,"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":["posix","quotes","quoting-args","shell"],"created_at":"2024-08-17T08:06:58.837Z","updated_at":"2025-07-14T03:11:59.762Z","avatar_url":"https://github.com/vaeth.png","language":"Shell","funding_links":[],"categories":["shell"],"sub_categories":[],"readme":"# push\n\n(C) Martin Väth \u003cmartin@mvath.de\u003e\nThis project is under the BSD license 2.0 (“3-clause BSD license”).\nSPDX-License-Identifier: BSD-3-Clause\n\nA POSIX shell function to treat a variable like an array, quoting args.\n\nFor installation simply copy the content of bin/ somewhere into your path\nwith the executable bit being set or execute make (and \"make install\" as root).\n\nTo check from within a POSIX shell script whether Push 2.0 (or newer)\nis installed, and sourcing it if it is, you can use something like:\n\n```\nif SOME_VARIABLE=`push.sh 2\u003e/dev/null`\nthen\teval \"$SOME_VARIABLE\"\nelse\techo \"push.sh not installed\" \u003e\u00262\nfi\n```\n\n__Remark__: An obsoleted method was to use instead\n```\n\t. push.sh\n```\nThe latter works for older versions of push or if one installs manually,\nbut unless an appropriate PATH before sourcing is set, it fails when\npush.sh is replaced by a wrapper script which happens with the provided\nMakefile. Moreover, if push.sh is not available it stops the script.\n\nAfter this you have the shell function ```Push```.\n\n__Usage__: ```Push [-c] VARIABLE [arguments]```\n\nThe arguments will be appended to `VARIABLE` in a quoted manner (with\nquotes rarely used - the exact form depends on the version of `push.sh`)\nso that an `eval \"$VARIABLE\"` obtains the collected arguments (see examples).\nWith option `-c`, `VARIABLE` will be cleared before arguments are appended:\nThe first call for `VARIABLE` must always be done with `-c`.\nThe return value is zero if `$VARIABLE` contains at least one pushed argument.\n\nScripts using Push must not use variables of the form `Push*_` (the reason is\nthat POSIX does not provide a local name scope, and so `Push` uses internally\nglobal variables of such a form)\n\n## Example 1\n```\nPush -c foo 'data with special symbols like ()\"\\' \"'another arg'\"\nPush foo further args\neval \"printf '%s\\\\n' $foo\"\n# Be aware that not only $foo but the whole command is eval'ed!\n```\nwill output\n```\ndata with special symbols like ()\"\\\n'another arg'\nfurther\nargs\n```\n\n## Example 2\n### Remove the last argument from the argument list in a script\n```\nPush -c args\nwhile [ $# -gt 1 ]\ndo\tPush args \"$1\"\n\tshift\ndone\neval \"set -- a $args\"; shift\n# Note: \"set -- $args\" can break with some shells if args is empty\n```\n\n## Example 3\n### Quote a command for \"su\" correctly\n```\nPush -c files \"$@\" \u0026\u0026 su -c \"cat -- $files\"\n```\nuses `su` to `cat` files passed as arguments with root permissions,\neven if the arguments contain problematic symbols like spaces, `\u003c`, or quotes.\n\n## Example 4\n### Pretty-print a command without loosing exactness\n```\nset -- source~1 'source 2' \"source '3'\"\nPush -c v cp -- \"$@\" \\~dest\nprintf '%s\\n' \"$v\"\n```\nwill output a command which reliably can be pasted by the user\ninto a POSIX shell but which nevertheless is reasonably human-readable.\nThe exact form of output might be subject to change in different versions\nof Push. Currently the output would look like:\n```\ncp -- source~1 'source 2' 'source '\\'3\\' '~dest'\n```\nIt is not recommended to rely on any particular form of the output:\nInstead, `Push` itself should be used if information is needed as in\nthe subsequent example.\n\n## Example 5\n### Omitting arguments for Push can be useful\n```\nPush -c data\nSomeFunction\nPush data || echo 'nothing was pushed to $data in SomeFunction'\n```\nThis has the advantage that you need not rely on the implementation\ndetails of how Push stores the data in the variable (which may depend\non the version of Push).\n\n## AUTHORS\n\nMartin Väth \u003cmartin at mvath.de\u003e (Main part)\nxofyarg (fix in Makefile)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaeth%2Fpush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaeth%2Fpush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaeth%2Fpush/lists"}