1

When I executeinit-hooks I get

bash: init-hooks: command-not found

here are the contents of init-hooks:

#!/bin/bash
set -e
printf '\ncopying hooks\n\n'
cp ./hooks/* ../../.git/hooks

When I execute cp ./hooks/* ../../.git/hooks from bash directly execution is successful. (note this is the same command as what is in the script)

Proof of the files are in the directory and the results of execution: enter image description here

Why does my script behave differently than the command/why is my script not found?

jth41
  • 3,808
  • 9
  • 59
  • 109
  • 2
    Back in 1970s university systems you had jokers creating files with names like `/tmp/ls` that would usually play some kind of prank on the person invoking it (or "typosquatting", with names like `lls`, `sl` or the like, for places where `.` is at the end of the PATH rather than the beginning). One of the things about having a lot of history on multiuser systems is that one learns which practices are unsafe, and that knowledge gets that baked into software design. – Charles Duffy May 02 '17 at 16:33

2 Answers2

2

On the Linux systems (where bash comes from) the current directory is usually not included in the path for security reasons.

Run echo $PATH to check what directories are used to search for executables when they are provided in the command line without a path. The current directory (.) should not be there.

Run the script as ./init-hooks and bash will find it.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • 1
    And make sure the *execute bit* is set on `init-hooks` (e.g. `chmod 0755 init-hooks`) (or whatever permissions you want that includes the execute bit), otherwise run it as `bash init-hooks`. – David C. Rankin May 02 '17 at 16:29
  • The *execute bit* is set in this case; the asterisk (`*`) after the file name in the output of `ls` tells that. But it is a valuable advice, nevertheless. – axiac May 02 '17 at 16:42
  • Yes, I breezed right by that in the picture of the output for `ls`. Good catch. – David C. Rankin May 02 '17 at 17:25
0

I suugest to run it following way

./init_hooks

or put fully qualified file name.

make sure to make the script executable

chmod +x ./init_hooks

Oo.oO
  • 12,464
  • 3
  • 23
  • 45