zsh-workers
 help / color / mirror / code / Atom feed
* Command execution
@ 2021-11-15 11:40 aismtnt
  2021-11-15 13:33 ` Mikael Magnusson
  0 siblings, 1 reply; 3+ messages in thread
From: aismtnt @ 2021-11-15 11:40 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 650 bytes --]


Documentation: https://zsh.sourceforge.io/Doc/Release/Command-Execution.html

There is a statement in docs:

'If execution fails because the file is not in executable format,and the file is not a directory, it is assumed to be a shellscript. /bin/sh is spawned to execute it.'

I wonder if it's true or maybe I'm missing something.

My understanding is that if I create a file with shell commands but won't change its mode to executable, it will still be executed, because it is assumed to be a shell script.

But it does not.

```zsh
# Create file.
echo 'echo "Hello world"' > my_script

# Run file.
my_script
zsh: command not found: my_script
```

[-- Attachment #2: Type: text/html, Size: 1481 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Command execution
  2021-11-15 11:40 Command execution aismtnt
@ 2021-11-15 13:33 ` Mikael Magnusson
  2021-11-15 13:39   ` Roman Perepelitsa
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2021-11-15 13:33 UTC (permalink / raw)
  To: aismtnt; +Cc: zsh-workers

On 11/15/21, aismtnt@tutanota.com <aismtnt@tutanota.com> wrote:
>
> Documentation:
> https://zsh.sourceforge.io/Doc/Release/Command-Execution.html
>
> There is a statement in docs:
>
> 'If execution fails because the file is not in executable format,and the
> file is not a directory, it is assumed to be a shellscript. /bin/sh is
> spawned to execute it.'
>
> I wonder if it's true or maybe I'm missing something.
>
> My understanding is that if I create a file with shell commands but won't
> change its mode to executable, it will still be executed, because it is
> assumed to be a shell script.
>
> But it does not.

"executable format" refers to the contents of the file, eg will the
kernel exec()ute this, and "executable mode" refers to the mode of the
file, they are not the same thing. The quoted statement only applies
if execution failed because of the file contents not being a valid
executable format, but in your case the execution failed because of
missing permissions (earlier check), so the statement does not apply.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Command execution
  2021-11-15 13:33 ` Mikael Magnusson
@ 2021-11-15 13:39   ` Roman Perepelitsa
  0 siblings, 0 replies; 3+ messages in thread
From: Roman Perepelitsa @ 2021-11-15 13:39 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: aismtnt, Zsh hackers list

On Mon, Nov 15, 2021 at 2:33 PM Mikael Magnusson <mikachu@gmail.com> wrote:
> [...] in your case the execution failed because of
> missing permissions (earlier check)

It didn't get that far: "command not found" error implies a failed
search in PATH.

  % echo 'echo "Hello world"' >my_script

  % my_script
  zsh: command not found: my_script

  % path+=($PWD)
  % my_script
  zsh: permission denied: my_script

  % chmod +x my_script
  % my_script
  Hello world

Roman.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-15 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 11:40 Command execution aismtnt
2021-11-15 13:33 ` Mikael Magnusson
2021-11-15 13:39   ` Roman Perepelitsa

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).