Zprofile errors on Terminal Startup (MacOS) - shell

I'm getting errors whenever I startup my terminal- I got a new computer for bioinformatics, so it's relatively fresh. I haven't put much on here, except a couple basics- I suspect homebrew issues but I'm not sure where I went wrong. When I startup, I'm getting the following message just from opening Terminal:
Last login: Mon Jan 30 12:51:33 on ttys001
/Users/hdose/.zprofile:3: command not found: s
/Users/hdose/.zprofile:4: command not found: q
12:51 up 3 mins, 2 users, load averages: 112.81 28.51 10.54
USER TTY FROM LOGIN# IDLE WHAT
hdose console - 12:51 - -
hdose s000 - 12:51 - w
/Users/hdose/.zprofile:6: command not found: e
/Users/hdose/.zprofile:fc:7: current history line would recurse endlessly, aborted
/Users/hdose/.zprofile:fc:8: current history line would recurse endlessly, aborted
/Users/hdose/.zprofile:9: command not found: t
/Users/hdose/.zprofile:10: permission denied: /
/Users/hdose/.zprofile:.:11: not enough arguments
/Users/hdose/.zprofile:12: command not found: ,
/Users/hdose/.zprofile:32: unmatched '
I've checked
$open -e \~/.zprofile
Which returns:
echo '# Set PATH, MANPATH, etc., for Homebrew.' \>\> /Users/hdose/.zprofile
s
q
w
e
r
r
t
/
.
,
'
;
\\
> >
\<\<
/
?
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
Set PATH, MANPATH, etc., for Homebrew.
For some background, for home-brew install, I did:
$echo '# Set PATH, MANPATH, etc., for Homebrew.' \>\> /Users/hdose/.zprofile
$echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' \>\> /Users/hdose/.zprofile

Related

I have to reload shell (exec $SHELL -l) to load all PATHs on Fish shell

I set Fish as a login shell referenced here(https://fishshell.com/docs/current/index.html#default-shell).
Then installed rbenv.
But I have to reload Fish shell to call rbenv.
Easy to understand to look at below.
yas  ~  ps -f
UID PID PPID C STIME TTY TIME CMD
501 55722 55721 0 5:09PM ttys001 0:00.02 -fish //set fish as login shell
yas  ~  rbenv // couldn't find rbenv
fish: Unknown command: rbenv
yas  ~  echo $PATH // couldn't find a path to rbenv
/Users/yas/.anyenv/envs/pyenv/shims /opt/homebrew/bin /opt/homebrew/sbin /opt/homebrew/opt/openssl#1.1/bin /opt/homebrew/opt/openssl#3/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Users/yas/.anyenv/envs/pyenv/bin
yas  ~  exec $SHELL -l // Reloading the shell
yas  ~  rbenv --version // succeeded
rbenv 1.2.0-14-gc6cc0a1
yas  ~  echo $PATH // Paths are added after reloading the shell.
/Users/yas/.anyenv/envs/rbenv/shims /Users/yas/.anyenv/envs/pyenv/shims /opt/homebrew/bin /opt/homebrew/sbin /opt/homebrew/opt/openssl#1.1/bin /opt/homebrew/opt/openssl#3/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /opt/homebrew/bin /opt/homebrew/sbin /Users/yas/.anyenv/envs/pyenv/bin /Users/yas/.anyenv/envs/pyenv/bin /Users/yas/.anyenv/envs/rbenv/bin
yas  ~  ps -f // shell path has changed from -fish after reloading.
UID PID PPID C STIME TTY TIME CMD
501 55722 55721 0 5:09PM ttys001 0:00.16 /opt/homebrew/bin/fish -l
Inside ~/.config/fish/config.fish
if status is-interactive
# Commands to run in interactive sessions can go here
end
eval (/opt/homebrew/bin/brew shellenv)
status --is-interactive; and source (anyenv init -|psub)
set fish_function_path $fish_function_path "/Users/yas/.anyenv/envs/pyenv/versions/3.10.5/lib/python3.10/site-packages/powerline/bindings/fish"
powerline-setup
I don't like to type exec $SHELL -l on every launch.
Does anyone help me out with this?
This is https://github.com/anyenv/anyenv/pull/99 - anyenv's pyenv setup interferes with other envs:
In the current situation, pyenv init --path also causes a problem with anyenv. When logging into zsh, the initialization process stops at pyenv and further (such as rbenv, or sbtenv) are impossible.
As a workaround, it should be possible to just run anyenv init - twice, since it seems that the pyenv setup is skipped or succeeds the second time around (this would be what fixes it when you run fish twice!):
status --is-interactive; and source (anyenv init -|psub)
status --is-interactive; and source (anyenv init -|psub)
Which can be simplified to
if status is-interactive
anyenv init - | source
anyenv init - | source
end

zsh profile path is not reflected.. in terminal in Mac OS 11.2.3

I have installed mysql, trying to set path.
but somehow it does not reflect.
Is not Mysql compatible for zsh by any chance?
% brew list| grep mysql
mysql#5.7
echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.bash_profile
% echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
% source ~/.bash_profile
then
% mysql --version
zsh: command not found: mysql
You're using zsh in your terminal, so you need to add export PATH="/usr/local/opt/mysql#5.7/bin:$PATH" into your ~/.zshrc file.
If you don't have that file, do touch ~/.zshrc then add that to your Zsh config file.
Alternatively, if you want to switch back to Bash, just do chsh -s $(which bash) (without sudo to only take effect on current logged-in user) and then restart your shell.

Brew is installed but not identified as a command inside postinstall script of `pkgbuild` (MacOS)

I have a small shell script that installs Brew if it is not already installed.
#!/bin/bash -v
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
echo "Installing Brew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo "I don't think brew is installed..."
else
brew update
fi
The script runs fine when I run it as a standalone shell script. So I tried to create a package using the pkgbuild utility. But once inside the package the same script fails to identify Brew as a command, even though Brew is installed.
Things that I have tried so far:-
I enabled install logs and I can see
Sep 29 22:48:32 installd[80453]: ./postinstall:
/tmp/PKInstallSandbox.42j7tU/Scripts/org.mybinary.0.0.4.sDKM7K/postinstall:
line 16: brew: command not found
Used absolute path of the Brew binary /usr/local/bin/brew instead. This gave me a different but, nevertheless, still an error.
Sep 30 10:01:22 installd[90276]: ./postinstall: Error: Running Homebrew as root is extremely dangerous and no longer supported.
Sep 30 10:01:22 installd[90276]: ./postinstall: As Homebrew does not drop privileges on installation you would be giving all
Sep 30 10:01:22 installd[90276]: ./postinstall: build scripts full access to your system.
What am I missing?
Thanks!

Tomatousb, ls command is broken and returns just the query

I made ipkg upgrade on my old tomatousb, which it seems resulted at least in a broken ls command:
[root#tomatousb root]$ /bin/ls /
/
[root#tomatousb root]$ ls /bin
/bin
however, the results are displayed in different colours.
There is also strange behaviour:
[root#tomatousb root]$ echo $PATH
echo $PATH
sh: echo: Permission denied
[root#tomatousb root]$ /bin/echo $PATH
/bin/echo $PATH
/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin
I have no glue what's wrong to it.
The logs I see are as following:
/var/log/messages
Jan 1 04:00:11 tomatousb user.info kernel: ipt_recent v0.3.1: Stephen Frost <sfrost#snowman.net>. http://snowman.net/projects/ipt_recent/
Jan 31 23:10:21 tomatousb user.notice root: <<<< MPCSD: Config-files not found in /jffs/config/mpcs & /opt/etc/mpcs!!! Exit. >>>>
Jan 31 23:11:02 tomatousb cron.err crond[143]: time disparity of 25290430 minutes detected
Jan 31 23:37:26 tomatousb authpriv.info dropbear[505]: Child connection from *.*.*.*:*
So, basically, when I do SSH, I get to dropbear.
It seems that during the last ipkg upgrade I got new bash, tcpdump, and two more items, but I can't recall which exactly.. And I can't find the ipkg logfile...
Finally I bumped into my own old discussion when I had the same issue with the same box, and here's what was the reason:
[root#tomatousb mnt]$ cat /opt/etc/profile
#
# Bash initialization script
#
PS1="[\u#\h \W]$ "
PATH=/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin
LD_LIBRARY_PATH=/opt/lib:${LD_LIBRARY_PATH}
export PS1 PATH LD_LIBRARY_PATH
[root#tomatousb mnt]$ rm /opt/etc/profile
Then I did reboot, and everything restored back to normal operation!
Do not know what exactly was in that profile file that ruined everything and caused 'memory exhausted' error when running vi.

Rbenv not working

I installed ruby 2.0 into ~/.rbenv/versions last and now nothing but that is available
$ rbenv versions
system
*ruby-1.9.3-p392 (set by /apps/test_app/.ruby-version)
ruby-2.0.0-p0
$ ruby -v
ruby 2.0.0.p0
$ env | grep PATH
PATH=/home/cbron/.rbenv/shims:/home/cbron/.rbenv/bin
$cat ~/.bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
$rbenv global
ruby-1.9.3-p392
$rbenv local
ruby-1.9.3-p392
$rbenv shell
rbenv: no shell-specific version configured
edit: now set the shell, still nothing.
$rbenv shell
ruby-1.9.3-p392
ruby -v still getting
ruby 2.0.0p0
I already sourced my bash_profile, even restarted the computer.
I had the same issue using zsh and this fixed it:
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshenv
$ echo 'eval "$(rbenv init -)"' >> ~/.zshenv
$ echo 'source $HOME/.zshenv' >> ~/.zshrc
$ exec $SHELL
So basically moving the lines from profile to env!
Extracted from rbenv readme:
rbenv shell
Sets a shell-specific Ruby version by setting the RBENV_VERSION
environment variable in your shell. This version overrides
application-specific versions and the global version.
$ rbenv shell jruby-1.7.1
When run without a version number, rbenv shell reports the current
value of RBENV_VERSION. You can also unset the shell version:
$ rbenv shell --unset
Note that you'll need rbenv's shell integration enabled (step 3 of the
installation instructions) in order to use this command. If you prefer
not to use shell integration, you may simply set the RBENV_VERSION
variable yourself:
$ export RBENV_VERSION=jruby-1.7.1
So in order to use it you need to specify the ruby version as rbenv shell argument (f.e. rbenv shell 2.0.0.p0, or set RBENV_VERSION (f.e. export RBENV_VERSION=2.0.0.p0)
TL;DR: just reinstall rbenv, unless you are as stubborn as me...
I had messed up permissions in the .rbenv folder, so the shims weren't loading because they didn't have execute permissions
chmod u+x ~/.rbenv/shims/*
Disclaimer
I had deeper permissions problems, rbenv wasn't even working, so I did other chmod u+x ... previously
chmod u+x ~/.rbenv/libexec/*
chmod u+x ~/.rbenv/**/bin/*
Probably easier and safer to just reinstall rbenv. But this was fun!

Resources