echo -e '#!/bin/bash\nsleep 10' > time_test.sh && chmod +x time_test.sh && time time_test.sh
time_test.sh: No such file or directory
real 0m0.186s
user 0m0.105s
sys 0m0.074s
I must be missing something..?
EDIT: I missed the error, partially because I was ignoring an error in a non-example script (it is added now). The moral seems to be that commands that run the script in some fashion need its location, where as other built-ins like cat
dont. So, maybe the better question is, is that a decent definition of which commands need the location, or I suppose just trial and error, if there is an error the script can't be found, to add the ./
or path information.. I suppose anything that fails without it being marked executable. I wonder which other common commands people use that encounter this.
.
in your PATH which you should not do. You have to execute the script like./time_test.sh
orbash time_test.sh
– jesse_b Apr 13 '22 at 21:53time
on the script. I need to have something similar totime time_test.sh
. I triedtime bash time_test.sh
already.bash time time_test.sh
says "/usr/bin/time: cannot execute binary file". – alchemy Apr 13 '22 at 21:57time ./time_test.sh
– jesse_b Apr 13 '22 at 21:57bash time ...
buttime bash ...
ortime ./time_test.sh
should absolutely not produce that – jesse_b Apr 13 '22 at 22:05./
works. So all commands that run a script have to be told where it is, versus builtins likecat
that can see it in the pwd..? – alchemy Apr 13 '22 at 22:28time
? How are you running it? – ctrl-alt-delor Apr 13 '22 at 22:33time
needs the explicit location of the script to run. – alchemy Apr 13 '22 at 22:37.
, then you should fix it. It is a serous security vulnerability (e.g. make an executable script calledls
, then try to check for its existence usingls
. Hopefully the script does nothing bad), and can also lead to much annoyance. – ctrl-alt-delor Apr 13 '22 at 23:04time_test.sh
means a file in the current working directory if we're about to read or write to the file. If we're about to executetime_test.sh
then by convention it means a file namedtime_test.sh
somewhere in$PATH
. Note.
is usually not in$PATH
, so to execute./time_test.sh
you need to explicitly write this./
. There are subtleties, e.g.bash time_test.sh
works because it reads the file (to interpret it, but the file does not need to be executable).time time_test.sh
is simple though: it tries to truly executetime_test.sh
, so it uses$PATH
. – Kamil Maciorowski Apr 13 '22 at 23:26