Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two files, the first is 'ax':

#!/usr/bin/env zsh

print "Params: $*"
cat $*

And another one 'tst':

#! /home/me/ax
A
B
C

When I am in sh/csh/bash shell:

> ./tst
./tst: line 2: A: command not found
./tst: line 3: B: command not found
./tst: line 4: C: command not found

When I am in zsh shell:

Params: ./tst
#! /IW/users-home/e640846/ax
A
B
C

Is there a standard way to have the behavior I get in the zsh shell in other shell?

precision: - bash version: 3.00.15-(1) release (x86_64-redhat-linux-gnu)

Thanks

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

An interpreted script can not have the interpreter in turn be another script, so the kernel exec*() fails with ENOEXEC.

At this point, POSIX requires that the shell interpret the script itself. SUSv3, "Command Search and Execution", 1.d.i.b second paragraph.

But zsh is not a POSIX shell. Instead, zsh looks at the #! line and tries to run that itself, passing it the original script as an argument. Which is what has happened here -- you didn't succeed in using ax as an interpreter for tst, handling the content of tst; you just passed tst as a parameter to ax.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.