{"id":24757234,"url":"https://github.com/christophgil/bash_return","last_synced_at":"2025-03-23T08:11:59.225Z","repository":{"id":271586393,"uuid":"913537374","full_name":"christophgil/bash_return","owner":"christophgil","description":"Bash builtin for fast returning numeric and string values from Bash functions","archived":false,"fork":false,"pushed_at":"2025-01-10T23:02:52.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T14:46:05.848Z","etag":null,"topics":["bash","bash-builtin","bash-scripting","bashbuiltin","extension","functions","performance","plugin","plugins","return","return-value"],"latest_commit_sha":null,"homepage":"","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/christophgil.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,"publiccode":null,"codemeta":null}},"created_at":"2025-01-07T21:57:13.000Z","updated_at":"2025-01-10T23:02:56.000Z","dependencies_parsed_at":"2025-01-08T17:34:32.355Z","dependency_job_id":"ac3a6967-9290-458d-baad-740a0a97989f","html_url":"https://github.com/christophgil/bash_return","commit_stats":null,"previous_names":["christophgil/bash_return"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_return","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_return/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_return/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christophgil%2Fbash_return/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christophgil","download_url":"https://codeload.github.com/christophgil/bash_return/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245072270,"owners_count":20556353,"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":["bash","bash-builtin","bash-scripting","bashbuiltin","extension","functions","performance","plugin","plugins","return","return-value"],"created_at":"2025-01-28T14:38:44.567Z","updated_at":"2025-03-23T08:11:59.201Z","avatar_url":"https://github.com/christophgil.png","language":"Shell","readme":"# bash_return\n\n# Summary\n\nThis  Bash extension written in C allows script functions to return numeric or string values.\n\nStatus: Experimental\n\n\nGenerally, two methods can be used to return results from functions to the caller of the function.\n(I) Using command substitution to capture the output may cause poor performance.\n(II) Storing the result in a global variable is less compact and requires two statements.\n\n\nWith this Bash extension, functions can be used in both ways depending on a command line switch.\nSee  [Details](./motivation.md).\n\n\n# Installation\n\nFirst [Install dependencies](./INSTALL_DEPENDENCIES.md)\n\nCompile:\n\n    compile_C.sh  bashbuiltin_cg_return.c\n\n# Usage\n\nThe compiled builtins must be loaded once.\n\n    enable -f /home/cgille/compiled/bashbuiltin_cg_return.so   init_retval set_retval\n\nThe Bash builtin *init_retval* must be called at the top of the function body.\nThe return value of the function is set  with the builtin *set_retval*.\n\n    square(){\n        init_retval\n        : Do something\n        set_retval $(($1*$1))\n    }\n\nWhen the function is called with the switch -$, then the returned value is obtained from a variable\nwhose name is stored in the global variable *RETVAL*.  Usage of a global variable is possible\nbecause Bash is not multi-threaded. Normally, dollar signs need to be quoted in UNIX shells. Note\nthat the dollar sign does not need to be quoted here because it is followed by a space. This rather\nunusual command line switch is unlikely to be used already.  Note that *-$* must be the first\nparameter. It is shifted out by *init_retval* and will not be in the argument list any more.\n\n    square -$  3\n    echo \"The Square of 3 is ${RETVAL}\"\n\nWithout the option *-$*, the result is printed to the standard output.\n\n    square 3\n\n# Example with Arrays\n\n    my_seq(){\n        init_retval\n        local int n=$1\n        local aa=()\n        for((i=0;i\u003cn;i++)); do\n            aa+=( $((i*i)) )\n        done\n        set_retval \"${aa[@]}\"\n    }\n    my_seq 10\n\n\nTo capture these numbers in an array variable, call it as follows.\n\n    my_seq -$ 10\n    numbers=(\"${RETVAL[@]}\")\n    echo \"There are ${#numbers[@]} numbers. These are ${numbers[@]}\"\n\n# Benchmarks\n\nPerforming 40000 function calls with the script *benchmark_set_retval.sh*\n\n    classical      51 Seconds\n    Novel method  1.2 Seconds\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophgil%2Fbash_return","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristophgil%2Fbash_return","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristophgil%2Fbash_return/lists"}