Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

zsh - $ZSH_VERSION not being printed

I have a test.zsh script that contains echo $ZSH_VERSION and it outputs nothing. From the command line, echo $ZSH_VERSION prints 5.8. Is there a reason why this variable is null inside a zsh script? I am runing macOS 11.1.

question from:https://stackoverflow.com/questions/65888803/zsh-version-not-being-printed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As pointed out in the comments, file name extensions like .zsh mean nothing to Unix shells. What matters when sourcing a script is the shebang on the first line of the script. If you want your script to be interpreted by zsh instead, then you need to put this as the first line of your script:

#!/bin/zsh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...