Skip to content

Instantly share code, notes, and snippets.

@danny-andrews
Last active September 5, 2023 20:48
Show Gist options
  • Save danny-andrews/3b7cf181bbc0c33c3b410f4ebdf7e623 to your computer and use it in GitHub Desktop.
Save danny-andrews/3b7cf181bbc0c33c3b410f4ebdf7e623 to your computer and use it in GitHub Desktop.

Revisions

  1. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -67,7 +67,7 @@ Quotes are only required for strings that contain special characters (e.g. space
    `git commit -m "Fix thing"`
    `git commit -m Fix`

    > **Note**: When writing npm scripts, prefer double quotes `"` to single `'` for better cross-compatability with Windows.
    > **Note**: When writing npm scripts, prefer double quotes (`"`) to single (`'`) for better cross-compatability with Windows.
    ---

  2. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,7 @@ Quotes are only required for strings that contain special characters (e.g. space

    ### Subcommands

    Many modern commands use a command-subcommand structure, like git. In the following example, `git` is the root command, and `commit` is the subcommand.
    Many modern command-line programs use a command-subcommand structure. In the following example, `git` is the root command, and `commit` is the subcommand.

    `git commit -m "Hi"`

  3. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -63,9 +63,9 @@ I prefer to put positional arguments before options/flags when possible, as I fi

    Quotes are only required for strings that contain special characters (e.g. spaces).

    : `git commit -m Fix thing`
    : `git commit -m "Fix thing"`
    : `git commit -m Fix`
    `git commit -m Fix thing`
    `git commit -m "Fix thing"`
    `git commit -m Fix`

    > **Note**: When writing npm scripts, prefer double quotes `"` to single `'` for better cross-compatability with Windows.
  4. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -16,17 +16,17 @@ Options are named arguments and come in two forms:

    `git commit -m "Fix"`

    - **Long**: Multi-letter options are preceeded by a `--` with values placed after (separated by a `=` or a space).
    - **Long**: Multi-letter options are preceeded by a `--` with values placed after (separated by a `=` or by a space).

    `git commit --message="Fix"` = `git commit --message "Fix"`
    `git commit --message="Fix"` 🟰 `git commit --message "Fix"`

    > **Note:** Spaces aren't *required* after options, but are *encouranged* for readability, because `git commit -m"Fix"` looks cramped.
    ---

    ### Flags

    Flags don't take a value and can be long or short.
    Flags represent boolean values. They are options which don't take a value and can be long or short.

    `git commit --dry-run -v`

    @@ -36,24 +36,24 @@ Flags don't take a value and can be long or short.

    When using multiple short flags, you can combine them into one.

    `ls -a -g -h` = `ls -agh`
    `ls -a -g -h` 🟰 `ls -agh` 🟰 `ls -gha`

    ---

    ### Ordering

    The order of options/flags does not matter.

    `ls -a -g` = `ls -g -a`
    `ls -a -g` 🟰 `ls -g -a`

    **However**, some commands require all options/flags to come before positional arguments.

    **FAILS**: `ls my-dir -a`
    **WORKS**: `ls -a my-dir`
    `ls my-dir -a`
    `ls -a my-dir`

    Thankfully, most modern commands are agnostic.

    `git add a.js -v` = `git add -v a.js`
    `git add a.js -v` 🟰 `git add -v a.js`

    I prefer to put positional arguments before options/flags when possible, as I find it easier to read.

    @@ -63,9 +63,9 @@ I prefer to put positional arguments before options/flags when possible, as I fi

    Quotes are only required for strings that contain special characters (e.g. spaces).

    **FAILS**: `git commit -m Fix thing`
    **WORKS**: `git commit -m "Fix thing"`
    **WORKS**: `git commit -m Fix`
    : `git commit -m Fix thing`
    : `git commit -m "Fix thing"`
    : `git commit -m Fix`

    > **Note**: When writing npm scripts, prefer double quotes `"` to single `'` for better cross-compatability with Windows.
  5. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,26 @@
    # Shell Command Structure Summary

    ### Arguments (Positional Arguments)
    ### Arguments (i.e. Positional Arguments)

    Positional arguments are passed as-is after the command name.
    Positional arguments are passed as-is after the command name. Order matters.

    `cat file1.txt file2.txt`

    ---

    ### Options (Named Arguments)

    Options take values and come in two types:
    - **Short**: One-letter options preceeded by a `-`. Values are placed after (usually separated by a space).
    Options are named arguments and come in two forms:

    - **Short**: One-letter options are preceeded by a `-` with values placed after (separated by a space).

    `git commit -m "Fix"`

    - **Long**: Multi-letter options preceeded by a `--`. Values are placed after (separated by `=` or a space).
    - **Long**: Multi-letter options are preceeded by a `--` with values placed after (separated by a `=` or a space).

    `git commit --message="Fix"` = `git commit --message "Fix"`

    > **Note:** Spaces aren't *required* after options, but are *encouranged* for readability, because `git commit -m"Fix"` looks cramped.
    ---

  6. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Shell Command Structure Summary

    ### Positional Arguments
    ### Arguments (Positional Arguments)

    Positional arguments are passed as-is after the command name.

  7. danny-andrews revised this gist Sep 5, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ Thankfully, most modern commands are agnostic.

    `git add a.js -v` = `git add -v a.js`

    I prefer to put positional arguments before options/flags when possible, as I find it easier easier to read.
    I prefer to put positional arguments before options/flags when possible, as I find it easier to read.

    ---

  8. danny-andrews revised this gist Mar 31, 2023. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -68,6 +68,12 @@ Quotes are only required for strings that contain special characters (e.g. space
    ---

    ### Subcommands

    Many modern commands use a command-subcommand structure, like git. In the following example, `git` is the root command, and `commit` is the subcommand.

    `git commit -m "Hi"`

    ### Summary

    ![CLI Anatomy](https://user-images.githubusercontent.com/14965732/229198794-6e2ce6b7-fe56-4bf7-8ddf-b1619af00bbd.png)
  9. danny-andrews revised this gist Mar 31, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ The order of options/flags does not matter.

    **However**, some commands require all options/flags to come before positional arguments.

    **FAILS**: `ls my-dir -a`
    **FAILS**: `ls my-dir -a`
    **WORKS**: `ls -a my-dir`

    Thankfully, most modern commands are agnostic.
  10. danny-andrews created this gist Mar 31, 2023.
    73 changes: 73 additions & 0 deletions shell-command-structure.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    # Shell Command Structure Summary

    ### Positional Arguments

    Positional arguments are passed as-is after the command name.

    `cat file1.txt file2.txt`

    ---

    ### Options (Named Arguments)

    Options take values and come in two types:
    - **Short**: One-letter options preceeded by a `-`. Values are placed after (usually separated by a space).

    `git commit -m "Fix"`

    - **Long**: Multi-letter options preceeded by a `--`. Values are placed after (separated by `=` or a space).

    `git commit --message="Fix"` = `git commit --message "Fix"`

    ---

    ### Flags

    Flags don't take a value and can be long or short.

    `git commit --dry-run -v`

    ---

    ### Combining Short Flags

    When using multiple short flags, you can combine them into one.

    `ls -a -g -h` = `ls -agh`

    ---

    ### Ordering

    The order of options/flags does not matter.

    `ls -a -g` = `ls -g -a`

    **However**, some commands require all options/flags to come before positional arguments.

    **FAILS**: `ls my-dir -a`
    **WORKS**: `ls -a my-dir`

    Thankfully, most modern commands are agnostic.

    `git add a.js -v` = `git add -v a.js`

    I prefer to put positional arguments before options/flags when possible, as I find it easier easier to read.

    ---

    ### Quotes

    Quotes are only required for strings that contain special characters (e.g. spaces).

    **FAILS**: `git commit -m Fix thing`
    **WORKS**: `git commit -m "Fix thing"`
    **WORKS**: `git commit -m Fix`

    > **Note**: When writing npm scripts, prefer double quotes `"` to single `'` for better cross-compatability with Windows.
    ---

    ### Summary

    ![CLI Anatomy](https://user-images.githubusercontent.com/14965732/229198794-6e2ce6b7-fe56-4bf7-8ddf-b1619af00bbd.png)