What prefix is used to run a script located in the current directory when it is not in PATH?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

What prefix is used to run a script located in the current directory when it is not in PATH?

Explanation:
To run a script from the current directory when it’s not in PATH, you must specify a path that points to that location. The prefix ./ denotes the current directory, so the command would be ./scriptname to execute the script located there. This works because PATH is not searched for the current directory by default, a security measure that prevents accidentally running programs from your present working directory. Once you prefix with ./, the shell knows to look in the current directory for the script, provided it has execute permission and, ideally, a proper shebang line. If it doesn’t have execute permission, you can either grant it with chmod +x scriptname or run it by explicitly invoking an interpreter, like bash ./scriptname. The other options don’t specify the current directory: an interpreter path alone doesn’t target the script’s location, and a bare ./ would refer to the directory itself rather than a runnable file, while ./scriptname fully specifies the file but isn’t the single prefix—the prefix is ./ and the full command includes the script name.

To run a script from the current directory when it’s not in PATH, you must specify a path that points to that location. The prefix ./ denotes the current directory, so the command would be ./scriptname to execute the script located there. This works because PATH is not searched for the current directory by default, a security measure that prevents accidentally running programs from your present working directory. Once you prefix with ./, the shell knows to look in the current directory for the script, provided it has execute permission and, ideally, a proper shebang line. If it doesn’t have execute permission, you can either grant it with chmod +x scriptname or run it by explicitly invoking an interpreter, like bash ./scriptname. The other options don’t specify the current directory: an interpreter path alone doesn’t target the script’s location, and a bare ./ would refer to the directory itself rather than a runnable file, while ./scriptname fully specifies the file but isn’t the single prefix—the prefix is ./ and the full command includes the script name.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy