# Lesson: Running Programs Using zsh Hey, folks! Let's dive into running programs using `zsh`. `zsh` is a powerful and flexible shell that makes working with command-line interfaces (CLI) efficient and enjoyable. As new coders, you'll often find yourself running various CLI-based programs. We'll cover some common ones like Python, Ruby, Node, Git, Homebrew, and text editors like `vi` and `nano`. We'll also look at process management tools like `ps` and `top`. ## What is `zsh`? `zsh` (Z shell) is an extended version of the Bourne Shell (`sh`), with many improvements and additional features. It's widely used for its user-friendly enhancements, such as advanced tab completion, customizable prompts, and powerful scripting capabilities. ## Running Programs in `zsh` ### Python Python is a popular programming language. To run a Python script, use the following command: ```zsh python3 script.py ``` **Example:** ```zsh python3 hello.py ``` This command runs the `hello.py` script using Python 3. ### Ruby Ruby is another programming language known for its simplicity and productivity. To run a Ruby script, use: ```zsh ruby script.rb ``` **Example:** ```zsh ruby hello.rb ``` ### Node.js Node.js is a runtime for executing JavaScript on the server. To run a Node.js script, use: ```zsh node script.js ``` **Example:** ```zsh node app.js ``` ### Git Git is a version control system for tracking changes in source code. Common Git commands include: - Clone a repository: ```zsh git clone https://github.com/user/repo.git ``` - Check the status of your repository: ```zsh git status ``` - Commit changes: ```zsh git commit -m "Your commit message" ``` ### Homebrew (`brew`) Homebrew is a package manager for macOS. Common commands include: - Install a package: ```zsh brew install package-name ``` **Example:** ```zsh brew install wget ``` - Update Homebrew and all packages: ```zsh brew update brew upgrade ``` ### Text Editors: `vi` and `nano` - Open a file in `vi`: ```zsh vi filename ``` **Example:** ```zsh vi hello.py ``` - Open a file in `nano`: ```zsh nano filename ``` **Example:** ```zsh nano hello.py ``` ### Process Management: `ps` and `top` - List currently running processes: ```zsh ps aux ``` - Monitor system processes in real-time: ```zsh top ``` ### Other Useful Commands - List files and directories: ```zsh ls -la ``` - Change directory: ```zsh cd directory-name ``` - Display the current directory: ```zsh pwd ``` - Create a new directory: ```zsh mkdir directory-name ``` ## Examples and Common Use Patterns ### Running a Python Script Let's say you have a Python script called `hello.py` with the following content: ```python print("Hello, world!") ``` To run this script, navigate to the directory containing `hello.py` and execute: ```zsh python3 hello.py ``` ### Using Git for Version Control Assume you're working on a project and want to commit your changes. You can check the status, add changes, and commit with the following commands: ```zsh git status git add . git commit -m "Initial commit" ``` ### Installing a Package with Homebrew If you need a tool like `wget` to download files from the internet, you can install it using Homebrew: ```zsh brew install wget ``` ### Editing a File with `nano` If you need to quickly edit a file called `config.txt`, you can open it in `nano`: ```zsh nano config.txt ``` ### Monitoring System Processes To check which processes are consuming the most resources, use the `top` command: ```zsh top ``` ## Cheat Sheet - **Python:** `python3 script.py` - **Ruby:** `ruby script.rb` - **Node.js:** `node script.js` - **Git:** `git clone`, `git status`, `git commit -m "message"` - **Homebrew:** `brew install package-name`, `brew update`, `brew upgrade` - **vi:** `vi filename` - **nano:** `nano filename` - **Process Management:** `ps aux`, `top` - **File Operations:** `ls -la`, `cd directory-name`, `pwd`, `mkdir directory-name` ## Exercise 1. Create a new directory named `my_project`. 2. Inside `my_project`, create a Python script called `hello.py` that prints "Hello, world!". 3. Initialize a Git repository in `my_project`. 4. Add and commit `hello.py` to the repository. 5. Install `wget` using Homebrew. 6. Use `nano` to create a new file named `README.md` and write a brief description of your project. Feel free to reach out with any questions or if you need further assistance. Happy coding! :) <3