Home Explore Blog CI



nushell

3rd chunk of `book/coming_from_bash.md`
024d0e49663e559cbcd66ac6745762e34bb71a120ec6730e0000000100000fb0
|                                      | `rm -t <path>`                                                | Move the given file to the system trash                           |
| `rm -rf <path>`                      | `rm -r <path>`                                                | Recursively removes the given path                                |
| `date -d <date>`                     | `"<date>" \| into datetime -f <format>`                       | Parse a date ([format documentation](https://docs.rs/chrono/0.4.15/chrono/format/strftime/index.html)) |
| `sed`                                | `str replace`                                                 | Find and replace a pattern in a string                            |
| `grep <pattern>`                     | `where $it =~ <substring>` or `find <substring>`              | Filter strings that contain the substring                         |
| `man <command>`                      | `help <command>`                                              | Get the help for a given command                                  |
|                                      | `help commands`                                               | List all available commands                                       |
|                                      | `help --find <string>`                                        | Search for match in all available commands                        |
| `command1 && command2`               | `command1; command2`                                          | Run a command, and if it's successful run a second                |
| `stat $(which git)`                  | `stat ...(which git).path`                                    | Use command output as argument for other command                  |
| `echo /tmp/$RANDOM`                  | `$"/tmp/(random int)"`                                        | Use command output in a string                                    |
| `cargo b --jobs=$(nproc)`            | `cargo b $"--jobs=(sys cpu \| length)"`                       | Use command output in an option                                   |
| `echo $PATH`                         | `$env.PATH` (Non-Windows) or `$env.Path` (Windows)            | See the current path                                              |
| `echo $?`                            | `$env.LAST_EXIT_CODE`                                         | See the exit status of the last executed command                  |
| `<update ~/.bashrc>`                 | `vim $nu.config-path`                                         | Update PATH permanently                                           |
| `export PATH = $PATH:/usr/other/bin` | `$env.PATH = ($env.PATH \| append /usr/other/bin)`            | Update PATH temporarily                                           |
| `export`                             | `$env`                                                        | List the current environment variables                            |
| `<update ~/.bashrc>`                 | `vim $nu.config-path`                                         | Update environment variables permanently                          |
| `FOO=BAR ./bin`                      | `FOO=BAR ./bin`                                               | Update environment temporarily                                    |
| `export FOO=BAR`                     | `$env.FOO = BAR`                                              | Set environment variable for current session                      |
| `echo $FOO`                          | `$env.FOO`                                                    | Use environment variables                                         |
| `echo ${FOO:-fallback}`              | `$env.FOO? \| default "ABC"`                                  | Use a fallback in place of an unset variable                      |
| `unset FOO`                          | `hide-env FOO`                                                | Unset environment variable for current session                    |

Title: Bash to Nushell: Command Equivalents (Continued)
Summary
This section compares Bash and Nushell commands, covering file removal, date parsing, string manipulation, command help, command chaining, argument passing, environment variables, and fallback mechanisms. It highlights Nushell equivalents for Bash commands like `rm`, `date`, `sed`, `grep`, `man`, `&&`, `stat`, `echo $RANDOM`, `cargo b --jobs=$(nproc)`, `echo $PATH`, `echo $?`, `export`, and `unset`. It shows how to remove files, parse dates, perform string replacement and filtering, access command help, chain commands, pass command output as arguments, access and modify environment variables, and provide fallback values for unset variables.