{"id":20042622,"url":"https://github.com/code4mk/lets-bash","last_synced_at":"2026-06-04T22:31:41.695Z","repository":{"id":104452239,"uuid":"134991650","full_name":"code4mk/lets-bash","owner":"code4mk","description":"learn bash scripting with fun. ⇄ 0devco \u0026 code4mk","archived":false,"fork":false,"pushed_at":"2018-09-02T11:25:13.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T12:55:24.966Z","etag":null,"topics":["bash","bash-script","shell-script"],"latest_commit_sha":null,"homepage":"https://code4mk.org/linux4you/bash","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/code4mk.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}},"created_at":"2018-05-26T20:12:05.000Z","updated_at":"2018-09-02T11:25:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"5aea194c-2243-4002-91a3-500b02471423","html_url":"https://github.com/code4mk/lets-bash","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"57579d0b5a2d8b7ecd261b0c6dabc0f9fdc21c19"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Flets-bash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Flets-bash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Flets-bash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Flets-bash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code4mk","download_url":"https://codeload.github.com/code4mk/lets-bash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470459,"owners_count":19968047,"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-script","shell-script"],"created_at":"2024-11-13T10:52:31.889Z","updated_at":"2026-06-04T22:31:41.683Z","avatar_url":"https://github.com/code4mk.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n * visit for modern view [code4mk.org/linux4you/bash](https://code4mk.org/linux4you/bash)\n---\n# bash\n\n`bash` = `Bourne-Again SHell`\n\n# comments\n\n```bash\n# this is single line comment\necho \"kamal is a code artist\" # this is comment\n# output: kamal is a code artist\n```\n\n# variable\n\n## local variable\n\n```bash\nname=\"kamal\"\necho $name\n# output: kamal\n```\n* `local keyword uses inside function`\n\n```bash\nname=\"kamal\"\nuser(){\n  local name=\"jamal\"\n  echo $name\n}\necho $name\n#output:\n# jamal\n# kamal\n```\n\n## global variable\n\n```bash\nexport price=51\n```\n\n## default varibale\n\n```bash\nname=\"jamal\"\necho ${name:=\"kamal\"}\n# jamal\n```\n\n```bash\necho ${name:=\"kamal\"}\n# kamal\n```\n\n\n\n# string\n\n```bash\nstatus=\"Mostafa Kamal   is    a     code artist\"\necho $status\n# Mostafa Kamal is a code artist\necho \"$status\"\n# Mostafa Kamal   is    a     code artist\n```\n\n\n```bash\nname=\"kamal\"\necho 'this is $name'\n# thi is $name\necho \"this is $name\"\n# this is kamal\n```\n\n\n\n# arithmatic\n\n* `$(( .. ))`\n\n```bash\nx=5\ny=7\necho (( x + y ))\n# 12\n```\n\n\n# array\n\n```bash\nusers=(\"kamal\" \"jamal\" \"maruf\" \"sadia\")\necho ${users[1]}\n# output: jamal\nusers=(\"kamal\" \"jamal\" \"maruf\" \"sadia\")\necho ${users[@]} # [@] or [*] retrive all\n# output: kamal jamal maruf sadia\nusers=(\"kamal\" \"jamal\" \"maruf\" \"sadia\")\necho ${#users[@]}\n# output : 4\n# retrive array size\n```\n## array add\n\n```bash\nusers=(\"kamal\" \"jamal\" \"maruf\" \"sadia\")\nemployee=(\"kamrul\" \"${users[@]}\" \"faruk\")\necho ${employee[@]}\n# output: kamrul kamal jamal maruf sadia faruk\n```\n\n## array slice\n\n```bash\nusers=(\"kamal\" \"jamal\" \"maruf\" \"sadia\")\necho ${users[@]:1:2}\n# output: jamal maruf\n```\n## delete array ele\n\n```bash\nusers=(\"kamal\" \"jamal\" \"maruf\" \"sadia\")\nunset users[1]\necho ${users[@]}\n# output: kamal maruf sadia\n```\n# operator\n\n| arithmatic operator     | description     |\n| :------------- | :------------- |\n| -eq       | equal        |\n|-ne| not equal |\n|-lt|less than|\n|-le|less than or equal|\n|-gt|greater than|\n|-ge|greater than or equal|\n\n# condition\n\n* single squre bracket `[condition]` or double squre bracket `[[condtion]]`\n* ubuntu system basicaly not support `[[ not support ]]`\n  * access `[[ double]]` command `sudo bash myfile.sh`\n  * On Ubuntu systems, `/bin/sh` is `dash`, not `bash`, and `dash` does `not support` the `double bracket`\n\n## if\n\n```bash\nif [ 2 -eq 2 ]; then\n  echo \"the number is 2\"\nfi\n# output : the number is 2\n```\n\n## if-else\n\n```bash\nnumber=2\nif [ $number -eq 3 ]; then\n  echo \"the number is 2\"\nelse\n  echo \"the number is not 2\"\nfi\n# output : the number is 2\n```\n\n## elseif\n\n```bash\nnumber=2\nif [ $number -eq 3 ]; then\n  echo \"the number is 3\"\nelif [ $number -eq 2 ]; then\n  echo \"the number is 2\"\nelse\n  echo \"the number is not 2\"\nfi\n# output : the number is 2\n```\n\n## case\n\n```bash\nnumber=5\ncase $number in\n  2 )\n    echo \"the number is 2\"\n  ;;\n  3 )\n    echo \"the number is 3\"\n  ;;\n  * )\n    echo \"not 2 or 3\"\n  ;;\nesac\n# output: not 2 or 3\n```\n\n# loop\n\n## for\n\n```bash\nusers=(\"kamal\" \"jamal\" \"sadia\" \"maruf\")\nfor i in ${users[@]}; do\n  echo $i\ndone\n# kamal jamal sadia maruf\n```\n\n```bash\nfor (( i=0; i \u003c 10 ; i++)); do\n  echo $i\ndone\n# 0 1 2 3 4 5 6 7 8 9\n```\n\n### continue\n\n```bash\nfor (( i=0; i \u003c 10; i++)); do\n  if [ $(( i % 2 )) -eq 0]; then\n    continue\n  fi\n  echo $i\ndone\n# 1 3 5 7 9\n```\n\n### break\n\n```bash\nfor (( i=0; i \u003c 10; i++)); do\n  if [ $i -eq 5]; then\n    break\n  fi\n  echo $i\ndone\n# 0 1 2 3 4\n```\n\n## while\n\n```bash\ni=0\nwhile [ $i -lt 10 ]; do\n  echo $i\n  i=$(( i + 1 ))\ndone\n# 0 1 2 3 4 5 6 7 8 9\n```\n\n## until\n\n* `until` is opposite of `while`\n\n```bash\ni=0\nuntil [ $i -gt 10 ]; do\n  echo $i\n  i=$(( i + 1 ))\ndone\n# 0 1 2 3 4 5 6 7 8 9\n```\n\n\n# command\n\n## multiple command\n\n```bash\nuname\nid -u\nwhoami\n```\n## and \u0026\u0026 comannd\n\n```bash\nuname \u0026\u0026 id -u\n```\n\n## or || comannd\n\n```bash\nunamed || id -u\n# unamed is wrong command\n# uname is actual command\n```\n\n# function\n\n```bash\nread name\ncreate(){\n  adduser $1\n}\ncreate $name\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode4mk%2Flets-bash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode4mk%2Flets-bash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode4mk%2Flets-bash/lists"}