To run a shell script in Linux, you can use the following steps:
Open a terminal window on your Linux system.
Navigate to the directory where the shell script is located using the cd
command.
Make the shell script executable using the chmod
command. For example:
chmod +x script.sh
This will give execute permission to the script.
./
command, followed by the name of the script. For example:./script.sh
This will run the script.sh
script in the current directory.
Alternatively, you can specify the full path to the script if it is not located in the current directory. For example:
/path/to/script.sh
Replace /path/to/script.sh
with the full path to the script.
Keep in mind that the script must have the appropriate permissions and shebang line in order to run properly. The shebang line is the first line of the script, and should contain the path to the shell interpreter that will be used to execute the script. For example:
#!/bin/bash
This tells the system to use the bash
shell to execute the script.
You may also need to specify the full path to the shell interpreter if it is not in the system's PATH
environment variable. For example:
#!/usr/bin/env bash
This will use the bash
shell that is specified in the PATH
environment variable to execute the script.
If you are not sure which shell interpreter to use, you can use the #!/usr/bin/env
shebang line, which will use the default shell interpreter specified in the SHELL
environment variable.