Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: how to refer to basename of $0



Sorry folks, I'm explaining this really badly. Forget I said anything
about bash. I don't care about bash. I'm trying to leave bash behind.

Let me start over. Here's what happens in zsh 4.3.11

# my comments are offset with #
# fyi - "Air%" is my prompt

# just to show that $NAME is empty
	Air% echo $NAME
	Air%


# /tmp/.source has only one line:
	Air% cat /tmp/.source
	NAME=`basename $0`

# here is my 'test.zsh' script:
	Air% cat ./test.zsh
	#!/bin/zsh

	. /tmp/.source

	echo "$NAME"

  	exit 0

# So now I run 'test.zsh' :

	Air% ./test.zsh
	.source

# OK, so you can see that it output '.source' when I wanted it to
output 'test.zsh'

# Next: rename /tmp/.source to ~/.zshenv

	Air% mv /tmp/.source ~/.zshenv

# Edited 'test.zsh'  is now this:

	Air% cat =test.zsh
	#!/bin/zsh

	echo "$NAME"

	exit 0
	#EOF

# now when I run 'test.zsh' again:

	Air% test.zsh
	zsh

# Someone suggested "unsetopt function_argzero" so I added that to .zshenv:

	Air% cat ~/.zshenv
	unsetopt function_argzero

	NAME=`basename $0`

# and re-ran test.zsh, which gave me:

	zsh


Is it even possible to set NAME in .zsh* (and have it return
'test.zsh' or are they called too early in the process?

TjL



Messages sorted by: Reverse Date, Date, Thread, Author