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.shorbash time_test.sh– jesse_b Apr 13 '22 at 21:53timeon the script. I need to have something similar totime time_test.sh. I triedtime bash time_test.shalready.bash time time_test.shsays "/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.shshould 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 likecatthat 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:33timeneeds 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.shmeans 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.shthen by convention it means a file namedtime_test.shsomewhere in$PATH. Note.is usually not in$PATH, so to execute./time_test.shyou need to explicitly write this./. There are subtleties, e.g.bash time_test.shworks because it reads the file (to interpret it, but the file does not need to be executable).time time_test.shis simple though: it tries to truly executetime_test.sh, so it uses$PATH. – Kamil Maciorowski Apr 13 '22 at 23:26