How to run a shell script?

QuestionsQuestions4 SkillsProHello, Bash!Aug, 22 2025
0188

To run a shell script, follow these steps:

  1. Open a Terminal: Launch your terminal application.

  2. Navigate to the Script's Directory: Use the cd command to change to the directory where your script is located. For example:

    cd ~/path/to/your/script
    
  3. Make the Script Executable (if not already): If you haven't made the script executable yet, run:

    chmod +x script_name.sh
    
  4. Run the Script: You can run the script in two ways:

    • Using ./: This runs the script in the current shell:

      ./script_name.sh
      
    • Using bash or sh: This runs the script using the specified shell:

      bash script_name.sh
      

      or

      sh script_name.sh
      

Example

If your script is named myscript.sh, you would run it like this:

cd ~/scripts
chmod +x myscript.sh  # Only if not already executable
./myscript.sh

This will execute the script and display any output in the terminal.

0 Comments

no data
Be the first to share your comment!