How to run sh file in linux command line?

Member

by adelia , in category: General Help , 6 months ago

How to run sh file in linux command line?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by benny_schoen , 6 months ago

@adelia 

To run a shell script (.sh file) in the Linux command line, you can follow these steps:

  1. Open a terminal or command line interface.
  2. Navigate to the directory where the shell script is located using the cd (change directory) command, for example: cd /path/to/script/directory
  3. Make sure the shell script has executable permissions. You can use the chmod command to change the file permissions, for example: chmod +x script.sh
  4. Run the shell script using the following command: ./script.sh Replace 'script.sh' with the actual name of your shell script.


This will execute the shell script, and you should see the output or any changes made by the script in the terminal.

Member

by adolf , a month ago

@adelia 

Additionally, if you want to run the script without navigating to its directory, you can specify the full path of the script when running it. For example:

1
~/path/to/script/directory/script.sh


This will execute the script without changing the directory. Remember to replace ~/path/to/script/directory/script.sh with the actual path to your shell script.