A shell script is a file that contains a series of commands that can be executed by a shell interpreter. To execute a shell script, there are two main methods:
Method 1: Specify the path to the script file. This method requires that the script file has the execute permission, which can be granted by using the chmod command. The script file also needs to have a shebang line at the beginning, which indicates which interpreter to use for the script. For example, #!/bin/bash means to use the bash interpreter. To execute the script using this method, you can type the absolute path or the relative path to the script file. If you are in the same directory as the script file, you can use the ./ prefix to indicate the current directory. For example, ./test.sh will execute the test.sh script in the current directory.
Method 2: Pass the script file as an argument to the interpreter. This method does not require the execute permission or the shebang line for the script file. You can simply use the name of the interpreter followed by the script file name as an argument. For example, bash test.sh will execute the test.sh script using the bash interpreter.
Therefore, the correct answers are D and E. A. run test.sh is incorrect because run is not a valid command in Linux. B. ${test.sh} is incorrect because this syntax is used for variable expansion, not for executing a script. C. cmd ./test.sh is incorrect because cmd is not a valid command in Linux. References:
Linux Essentials Topic 105: The Power of the Command Line, section 105.3: Basic shell scripting.
How to Run a Shell Script in Linux [Essentials Explained] - It’s FOSS
How To Execute a Command with a Shell Script in Linux | DigitalOcean
How To Run the .sh File Shell Script In Linux / UNIX
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit