Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-bash: tea: command not found #648

Closed
Chasearmer opened this issue Jul 25, 2023 · 10 comments
Closed

-bash: tea: command not found #648

Chasearmer opened this issue Jul 25, 2023 · 10 comments

Comments

@Chasearmer
Copy link

I've run the command:
sh <(curl https://tea.xyz)

I accepted the installation for tea and the setup for tea magic. After doing so, I tried running the example commands:
wget -qO- tea.xyz/white-paper | glow -
and
node --eval 'console.log("node: hello world")'

Neither of these commands worked. I tried rerunning them prepended with tea, but I received the error in this issue's title, namely:
-bash: tea: command not found

I have tried closing and opening new terminals, and have rerun the sh <(curl https://tea.xyz) command. The command re-asks if I want to install, but does not re-ask if I want setup the tea magic -- it just says "you’re all set!", followed by the wget command that I referenced above.

@jhheider
Copy link
Contributor

What is your bash --version? I believe bash 3 (14 years old, shipped with macOS) is too old, and this causes issues. bash 4 and zsh should work fine.

If that's not at issue, check your ~/.bashrc to see if the tea magic line was added. You can try running it directly, and see if that changes anything.

If you're on bash 4, have the correct magic, and you still don't locate tea, then that's extremely mysterious. I assume: ~/.tea/tea.xyz/v0/bin/tea node --eval 'console.log("node: hello world")' does work, correct?

@Chasearmer
Copy link
Author

Hi @jhheider, thank you for the response!

It turned out that I did indeed have bash 3. However, upgrading to bash 5 did not resolve the problem (though the example code you provided did work correctly: ~/.tea/tea.xyz/v0/bin/tea node --eval 'console.log("node: hello world")').

I discovered that I also needed to add the following code to my .bash_profile:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

I can now run the commands in my original message, both with and without prepending tea.

Perhaps both of these steps would have been more obvious to a more experienced developer, and I certainly am not sure to what extent it is tea's responsibility to detect this kind of issue, but if it were possible to detect the bash version upon installation, maybe it could be helpful to newer users to include a warning message about older versions prior to bash 4?
I'm not sure if having a message somwhere about sourcing .bashrc in .bash_profile would be too much and too specific, but I feel I personally know a great deal of new developers who could get stuck on that step. But perhaps it was something unique to me that others wouldn't experience.

In any case, thank you for the help!

@jhheider
Copy link
Contributor

Interesting. I've never seen an install where .bashrc sourcing isn't default. Does bash 3 work (more) with the proper source line in .bash_profile?

What OS is this? The .bashrc thing is strange.

@Chasearmer
Copy link
Author

My macOS is 13.4.1 (c) (22F770820d)

My understanding of this may have gaps. However, as I understand it on a macOS system, when you open a new terminal (which by default is using Bash as the shell), the shell reads and executes the .bash_profile file. The .bashrc file is not read by default. Therefore, to automatically source the .bashrc, you must add the line discussed above to the .bash_profile:
if [ -f ~/.bashrc ]; then source ~/.bashrc; fi.

In your experience, is this line typically present in a .bash_profile? Is this line typically added by default (by some shell or other entity on macOS)?

Also, in regards to your question with bash 3, I changed by shell back to bash 3 and ran the following code:

(base) Chases-MBP:~ chasearmer$ echo $BASH_VERSION
3.2.57(1)-release
(base) Chases-MBP:~ chasearmer$ node --eval 'console.log("node: hello world")'
node: hello world
(base) Chases-MBP:~ chasearmer$ tea --help
usage:
  tea [-SEn] [+package~x.y…] [cmd|file|URL] [--] [arg…]

examples:
  $ tea node^19 --eval 'console.log("tea.xyz")'
  $ tea +nodejs.org man node
  $ tea +bun.sh sh
  # ^^ try out bun in a containerized shell

flags:
  --sync,-S       sync and update environment packages
  --env,-E        inject local environment
  --dry-run,-n    don’t do anything, just print

more:
  $ tea --verbose --help
  $ open https://docs.tea.xyz

It appears that it does work with bash 3, and that the issue was that my .bashrc was not being sourced. I noticed right before upgrading to bash 5 that I actually did not possess a .bashrc file. The .bashrc file was created upon upgrading my bash, and tea appeared to correct insert the magic line within it when I installed it after this upgrade. Not sure what role this information plays, if any, about my particular situation.

@jhheider
Copy link
Contributor

Interesting. So, we should possibly be populating the .bash_profile instead.

Since Catalina, the default configured shell on macOS is supposed to be zsh.

@Chasearmer
Copy link
Author

For the current approach, are you checking what SHELL the user is using, and then choosing to place the magic line in .bashrc if bash and .zshrc if zsh (and etc. for other shells)?

My current understanding is the following:
In macOS, when you open a new terminal window in iTerm2 (or the built-in Terminal.app), it starts a login shell. For Bash, a login shell reads and executes .bash_profile (or .bash_login or .profile if .bash_profile doesn't exist), but not .bashrc.

On the other hand, when you open a new terminal window with Zsh (the default as of macOS Catalina), it's also a login shell but it reads and executes both .zprofile and .zshrc.

@jhheider
Copy link
Contributor

Yes, we were only decorating the current shell, but that is migrating to looking for all shell configs. It sounds like we should use .bash_profile instead of .bashrc.

@jhheider
Copy link
Contributor

hm, actually:

https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

The bash manual says the files invoked are non-overlapping. It's "typical" for .bash_profile to invoke .bashrc, for exactly this reason.

It might be that we should instead check .bash_profile invokes .bashrc, or issue some kind of notice/warning. This isn't as simple as expected.

@jhheider
Copy link
Contributor

Need to consider the best approach here. At best, if your .bash_profile isn't invoking your .bashrc it seems like a misconfiguration, according to the GNU Bash manual. Solving it might be beyond tea's scope, but pkgxdev/setup#172 is open to exploring it.

@mxcl
Copy link
Member

mxcl commented Sep 11, 2023

v1 invokes in both (which is currently slow (not too bad), but we will speed it up).

We also changed the generally suggested invocations to eval "$(tea foo)" to avoid the source syntax issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants