You are in /home/ann/tools, where deploy.sh exists, begins with #!/bin/bash and carries the execute bit for your user. Typing `deploy.sh` returns "command not found". What is the cause, and what runs it?
LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium
Machine-checked — no person has signed for it. This question was read against the source cited below by an automated pass, which found no contradiction. That is a weaker claim than it sounds: the same kind of process wrote the question, so it can confirm its own mistake.
Treat it as a good draft rather than as settled fact, and read the source below before you rely on it. It is not used in mock exams here — only questions a person has signed for are.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
The options
Correct The current directory is not in PATH; run it as ./deploy.sh
Correct. A command name containing no slash is looked for only in the PATH directories, and . is deliberately absent from PATH on a normal Linux system. Writing ./deploy.sh makes the name a path, so no search happens.
Not correct The execute bit is not enough for a script; run chmod 777 deploy.sh first
Wrong. Execute permission for the invoking user is exactly what a script needs, and the stem says it is set. Granting write and execute permission to everyone would change nothing about the lookup failure.
Not correct The interpreter cannot be found; change the shebang to #!/usr/bin/env bash
Wrong. A missing interpreter produces a different error, and it comes from the kernel executing the file — meaning the file was found. "command not found" is emitted before that stage.
Not correct Scripts must live in a PATH directory; move it to /usr/local/bin
Wrong as a diagnosis, even though it would work. The script does not have to move: naming it with a path, as ./deploy.sh or /home/ann/tools/deploy.sh, runs it where it is.
Why
Bash decides between a PATH search and a direct execution by looking for a slash in the command word. No slash means search PATH; any slash at all means treat the word as a path, relative or absolute. Leaving . out of PATH is a security measure: a file called ls dropped in a shared directory would otherwise run in place of the real one.
Where this comes from
- Cited
- manual page bash(1)
Practise this
Reading one question is not practice. The trainer will draw a short set from objective 103 and space the ones you get wrong.
More questions on this objective
- A user starts a new terminal window in a running graphical desktop session, which launches bash as an interactive shell that is NOT a login shell. Which file in the user's home directory does bash read in that case? machine-checked
- In bash, which history expansion re-runs the entire previous command line? machine-checked
- Which bash command prints the literal five characters $USER instead of the current user name? machine-checked
- You want /opt/bin searched for executables, after all the directories already in PATH, in the current bash session and in every command started from it. Which command does that? machine-checked
- There is a passwd manual page in section 1 (the command) and another in section 5 (the /etc/passwd file format). Which command opens the section 5 page? machine-checked
- Select the TWO true statements about shell variables and the environment in bash. machine-checked