{"id":13503249,"url":"https://github.com/zombieleet/bashify","last_synced_at":"2025-03-29T14:31:15.756Z","repository":{"id":86824605,"uuid":"68767031","full_name":"zombieleet/bashify","owner":"zombieleet","description":"few helper functions in bash ( especially string manipulation functions )","archived":false,"fork":false,"pushed_at":"2016-12-19T16:17:42.000Z","size":14,"stargazers_count":100,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-31T23:30:55.728Z","etag":null,"topics":[],"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/zombieleet.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}},"created_at":"2016-09-21T01:19:24.000Z","updated_at":"2024-09-09T22:43:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"c010e1e7-321b-4cf7-bccf-662f6e1286f3","html_url":"https://github.com/zombieleet/bashify","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/zombieleet%2Fbashify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombieleet%2Fbashify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombieleet%2Fbashify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zombieleet%2Fbashify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zombieleet","download_url":"https://codeload.github.com/zombieleet/bashify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246196911,"owners_count":20739192,"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-07-31T22:02:43.479Z","updated_at":"2025-03-29T14:31:15.464Z","avatar_url":"https://github.com/zombieleet.png","language":"Shell","readme":"# bashify\nfew helper functions in bash\n\n#repeatString\nrepeats a string \n\n``` bash\nrepeatString string ?depth\n\n#depth \u003e\u003e how many times to repeat the string\n\nrepeatString \"bash\" 5 # bashbashbashbashbash\n```\n\n#charAt\n\nget the position of a character in a string\n\n```bash\ncharAt string positionToSearch\n\ncharAt \"bash\" 2 # a\n```\n\n#includes\n\ncheck if a word is in a string\n\n```bash\nincludes string stringToSearch ?depth\n\n#depth  where to start search from\n\nincludes \"bash\" sh 2\n\n#returns 1 for false or 0 for true\n```\n\n#endsWith\ncheck if a word is at the end of a string\n```bash\nendsWith string endToCheck ?depth\n\n# depth \u003e\u003e where to start the search from\n\nendsWith \"bash\" a 2\n\n#returns 1 for false or 0 for true\n```\n\n#isInteger\ncheck if a value is an integer\n\n```bash\nisInteger number\n\n#return 1 for non integers or 0 for integers\n\n```\n\n#int\nget all the integers before the decimal point\nnon integers values will throw an error\n\n```bash\nint number\nint 25.8 ; # 25\n```\n\n#destructure\n\nset the content of an array into different variables\n\ngotchas\n\ndo not quote the array argument ( first agument )\n\nit is important you quote the second argument to this function\n          \nassociative arrays work in alphabetical order\n          \nuse \",\" to separate the variables to assign each array element to\n          \n          \n```bash          \ndestructure array values\n\narray=( bash ksh zsh )\n\ndestructure ${array[@]} \"shell1,,shell2\"\n\necho $shell1  # bash\n\necho $shell2  # zsh\n\ndestructure ${array[@]} \"shell1,shell2,shell3\"\n\necho $shell1 # bash\n\necho $shell2 # ksh\n\necho $shell3 # zsh\n\n```\n\n#...\nSpread a bunch of string inside an array\n\n```bash\n... string\n\nstr=bash\n\narray=( $(... $str) )\n\necho ${str[@]} # b a s h\n```\n\n#foreach\nforeach element of an array execute a function \n\ngotchas: \n\ndon't quote the array arugment ( i.e the first argument )\n\nIf you pass in a function as a callback using the function command you should wrap it in single quote\n\n\n```bash\n\ns() { echo $(( $1 * $1 )) ;}\n\narray=( 1 2 3 4 5 6 )\n\nforeach ${array[@]} s # 2 4 6 8 10 12\n\nforeach ${array[@]} 'function s() { echo $(( $1 + $1 )) ;}' # always end the function with a ;} \n# 2 4 6 8 10 12\n\n```\n\n\n#copyWithin\ncopy an array index into another index\nquote the first argument use ${array[\\*]} instead of ${array[@]}\n\n```bash\n\ncopyWithin arrayArgument indexToCopyfrom indexToCopyTo\n\narray=( \"bash\" \"ksh\" \"zsh\" \"csh\" )\n\ncopyWithin \"${array[*]}\" 1 3 # bash ksh zsh ksh\n\n```\n","funding_links":[],"categories":["Shell","Libraries","Shell Script Development","Helper Function Things"],"sub_categories":["Reusable Things"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzombieleet%2Fbashify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzombieleet%2Fbashify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzombieleet%2Fbashify/lists"}