{"id":19526373,"url":"https://github.com/ogty/shell-script-getting-started","last_synced_at":"2026-04-19T01:03:21.321Z","repository":{"id":118760811,"uuid":"468984457","full_name":"ogty/shell-script-getting-started","owner":"ogty","description":"🐚 Shell Script Getting Started","archived":false,"fork":false,"pushed_at":"2022-04-19T07:57:41.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T09:47:14.360Z","etag":null,"topics":["bash","getting-started","shell","shell-script"],"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/ogty.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":"2022-03-12T05:03:04.000Z","updated_at":"2022-10-22T08:20:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ed9995d-d124-4a39-86b8-1b2063779b8b","html_url":"https://github.com/ogty/shell-script-getting-started","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/ogty%2Fshell-script-getting-started","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogty%2Fshell-script-getting-started/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogty%2Fshell-script-getting-started/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ogty%2Fshell-script-getting-started/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ogty","download_url":"https://codeload.github.com/ogty/shell-script-getting-started/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240777562,"owners_count":19855857,"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","getting-started","shell","shell-script"],"created_at":"2024-11-11T01:09:40.204Z","updated_at":"2026-04-19T01:03:21.257Z","avatar_url":"https://github.com/ogty.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shell Script Getting Started\n\n## Contents\n\n- [Contents](https://github.com/ogty/shell-script-gs/blob/master/README.md#contents)\n- [Getting Started](https://github.com/ogty/shell-script-gs/blob/master/README.md#getting-started)\n    - [Output](https://github.com/ogty/shell-script-gs/blob/master/README.md#output)\n    - [Format Strings](https://github.com/ogty/shell-script-gs/blob/master/README.md#format-strings)\n    - [Positional Parameters](https://github.com/ogty/shell-script-gs/blob/master/README.md#positional-parameters)\n    - [User Input](https://github.com/ogty/shell-script-gs/blob/master/README.md#user-input)\n    - [Reading a File](https://github.com/ogty/shell-script-gs/blob/master/README.md#reading-a-file)\n    - [Variables](https://github.com/ogty/shell-script-gs/blob/master/README.md#variables)\n    - [If Statements](https://github.com/ogty/shell-script-gs/blob/master/README.md#if-statements)\n    - [While Loop](https://github.com/ogty/shell-script-gs/blob/master/README.md#while-loop)\n    - [For Loop](https://github.com/ogty/shell-script-gs/blob/master/README.md#for-loop)\n    - [Case Statement](https://github.com/ogty/shell-script-gs/blob/master/README.md#case-statement)\n    - [Functions](https://github.com/ogty/shell-script-gs/blob/master/README.md#functions)\n- [Commands](https://github.com/ogty/shell-script-gs/blob/master/README.md#commands)\n    - [Regular Expressions](https://github.com/ogty/shell-script-gs/blob/master/README.md#regular-expressions)\n    - [grep](https://github.com/ogty/shell-script-gs/blob/master/README.md#grep)\n    - [find](https://github.com/ogty/shell-script-gs/blob/master/README.md#find)\n    - [file](https://github.com/ogty/shell-script-gs/blob/master/README.md#file)\n    - [cut](https://github.com/ogty/shell-script-gs/blob/master/README.md#cut)\n    - [head](https://github.com/ogty/shell-script-gs/blob/master/README.md#head)\n    - [tail](https://github.com/ogty/shell-script-gs/blob/master/README.md#tail)\n    - [sort](https://github.com/ogty/shell-script-gs/blob/master/README.md#sort)\n    - [xxd](https://github.com/ogty/shell-script-gs/blob/master/README.md#xxd)\n    - [wevtutil](https://github.com/ogty/shell-script-gs/blob/master/README.md#wevtutil)\n    - [uniq](https://github.com/ogty/shell-script-gs/blob/master/README.md#uniq)\n    - [join](https://github.com/ogty/shell-script-gs/blob/master/README.md#join)\n    - [sdiff](https://github.com/ogty/shell-script-gs/blob/master/README.md#sdiff)\n    - [base64](https://github.com/ogty/shell-script-gs/blob/master/README.md#base64)\n    - [curl](https://github.com/ogty/shell-script-gs/blob/master/README.md#curl)\n    - [vi commands](https://github.com/ogty/shell-script-gs/blob/master/README.md#vi-commands)\n    - [tr](https://github.com/ogty/shell-script-gs/blob/master/README.md#tr)\n- [Others](https://github.com/ogty/shell-script-gs/blob/master/README.md#others)\n\n---\n\n## Getting Started\n\n### Output\n\nWriting to the screen \n\n```sh\necho 'Hello, world!'\nprintf 'Hello, world!'\n```\n\n### Format Strings\n\nFormat strings for `printf`\n\n- `%s` : String\n- `%d` : Decimal\n- `%f` : Floating point\n- `%x` : Hexadecimal\n- `\\n` : Newline\n- `\\r` : Carriage return\n- `\\t` : Horizontal tab\n\n### Positional Parameters\n\nScript parameters\n\n- `$#` : Number of parameters\n- `$0` : Name of the script\n- `$1` : First parameter\n- `$2` : Second parameter ...\n\nDefault parameters\n\n```sh\nMYVAR=${1:-Cake}\n```\n\nNote: If parameter 1 is unset, the value of `MYVAR` will default to `Cake`\n\n### User Input\n\nRead from stdin\n\n```sh\nread MYVAR\n```\n\nPrompting\n\n```sh\nread -p 'Name: ' USERNAME\n```\n\n### Reading a File\n\n```sh\nwhile IFS=\"\" read MYLINE\ndo\n    echo \"$MYLINE\"\ndone \u003c \"somefile.txt\"\n```\n\nNote: `IFS=\"\"` preserves whitespace\n\n### Variables\n\nDeclaring a Variable\n\n```sh\nMYVAR='Hello'\n```\n\nReferencing a Variable\n\n```sh\necho $MYVAR\necho \"$MYVAR, world!\"\n```\n\nAssigning Shell Output\n\n```sh\nCMDOUT=$(pwd)\n```\n\n### If Statements\n\nCommand conditional(`cmd` will return `0` if success)\n\n```sh\nif cmd\nthen \n    some cmds\nelse\n    other cmds\nfi\n```\n\nFile and numeric conditionals\n\n```sh\nif [[ -e $FILENAME ]]\nthen\n    echo $FILENAME exists\nfi\n```\n\n| File Test | Use                |\n| --------- | ------------------ |\n| -d        | Derectory exists   |\n| -e        | File exists        |\n| -r        | File is readable   |\n| -w        | File is writable   |\n| -x        | File is executable |\n\n| Numeric Test | Use          |\n| ------------ | ------------ |\n| -eq          | Equal        |\n| -gt          | Greater than |\n| -lt          | Less than    |\n\n### While Loop\n\n```sh\ni=0\nwhile (( i \u003c 1000 ))\ndo\n    echo $i\n    let i++\ndone\n```\n\n### For Loop\n\nNumerical looping\n\n```sh\nfor ((i=0; i \u003c 1000; i++))\ndo\n    echo $i\ndone\n```\n\nIterating over a list\n\n```sh\nfor VAL in 20 3 dog 7\ndo\n    echo $VAL\ndone\n```\n\n### Case Statement\n\n```sh\ncase $MYVAR in\n    \"carl\")\n        echo 'Hi Carl!'\n        ;;\n    \"Paul\")\n        echo 'Hi Paul!'\n        ;;\n    *) # default\n        echo 'Goodbye'\n        exit\n        ;;\nesac\n```\n\n### Functions\n\nDeclaring a function\n\n```sh\nfunction myfun ()\n{\n    # function body\n    echo 'This is myfunc()'\n}\n```\n\nInvoking a function\n\n```\nmyfun param1 param2\n```\n\n---\n\n## Commands\n\n### Regular Expressions\n\n| Character | Meaning                                       |\n| --------- | --------------------------------------------- |\n| .         | Single wildcard character                     |\n| ?         | Preceding item is optional                    |\n| \\*        | Match the preceding item zero or more times   |\n| +         | Match the preceding item one or more times    |\n| ^         | Anchor pattern to the beginning of the string |\n| $         | Anchor pattern to the end of the string       |\n| [ ]       | Character classes and ranges                  |\n| ( )       | Group                                         |\n| { }       | Quantifier                                    |\n\n### grep\n\nSearch the contens of file\n\n- `-c` : Count matching lines\n- `-E` : Enable extended regex\n- `-i` : Ignore case\n- `-P` : Enable Perl regex\n- `-R` : Recursively search\n\n### find\n\nSearch the system for files\n\n- `-exec` : Execute specified command for each file found\n- `-name` : Search by filename\n- `-size` : Search by file size\n- `-type` : Search by file type\n\n### file\n\nIdentify file type by magic number\n\n- `-f` : Read list from specified file\n- `-k` : List all type matches\n- `-z` : Look inside compressed files\n\n### cut\n\nExtract portions of data from a file\n\n- `-c` : Character(s) to extract\n- `-d` : Field delimiter\n- `-f` : Field(s) to extract\n\n### head\n\nOutput the first few lines/bytes of file\n\n- `-n` : Number of lines to output\n- `-c` : Number of bytes to output\n\n### tail\n\nOutput the last few lines of a file\n\n- `-f` : Continuously monitor end of file\n- `-n` : Number of lines to output\n\n### sort\n\nOrder the lines of a file\n\n- `-r` : Sort in descending order\n- `-f` : Ignore case\n- `-n` : Use numerical ordering\n- `-k` : Sort based on key\n- `-o` : Write output to file\n\n### xxd\n\nDisplay file in binary or hexadecimal\n\n- `-b` : Display using binary rather than hex\n- `-l` : Print specified number of bytes\n- `-s` : Start printing at specified position\n\n### wevtutil\n\nView and manage Windows logs\n\n- `el` : Enumerate available logs\n- `qe` : Query a log's events\n- `/c` : Specify max number of events\n- `/f` : Format output as XML\n- `/rd` : Read direction, if true read most recent first\n\n### uniq\n\nRemove duplicate lines from a file\n\n- `-c` : Print number of times line is repeated\n- `-f` : Ignore the specified number of fields\n- `-i` : Ignore case\n\n### join\n\nCombine two files\n\n- `-j` : Join using specified field\n- `-t` : Field delimiter\n\n### sdiff\n\nCompare two files\n\n- `-a` : Treat files as text\n- `-i` : Ignore case\n- `-s` : Suppress common lines\n- `-w` : Max characters to output per line\n\n### base64\n\nEncode/decode data using Base64\n\n- `-d` : Decode\n\n### curl\n\nNetwork data transfer\n\n- `-A` : Specify user agent\n- `-d` : Send using HTTP POST\n- `-G` : Send using HTTP GET\n- `-I` : Only fetch header\n- `-L` : Follow redirects\n- `-s` : Do not show errors\n\n### vi commands\n\n- `b` : Back one word\n- `cc` : Replace current line\n- `cw` : Replace current word\n- `dw` : Delete current word\n- `dd` : Delete current line\n- `w` : Forward one word\n- `:q!` : Quit without save\n- `:wq` : Quit with save\n- `/` : Search forward\n- `?` : Search backward\n- `n` : Find next occurrence\n\n### tr\n\nTranslate one character to another\n\n- `-d` : Delete character\n- `-s` : Squeeze repeated characters\n\n---\n\n## Others\n\n```bash\n$ curl -L -o output.html https://www.oreilly.com\n$ curl -LI https://www.oreilly.com\n$ curl -LIs https://www.oreilly.com | grep '200'\n```\n\n```\n$ sudo apt-get install wget\n$ wget -p -m -k -P ./mirror https://www.digadel.com\n```\n\n| Server/Protocol | Port Number |\n| --------------- | ----------- |\n| FTP             | TCP 21      |\n| SMTP            | TCP 25      |\n| HTTP            | TCP 80      |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogty%2Fshell-script-getting-started","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fogty%2Fshell-script-getting-started","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fogty%2Fshell-script-getting-started/lists"}