duplicate paths found in tmux mac - bash

i have a mac terminal where i have a tmux session running. When i call my env variable, i get duplicate paths that repeat. I tried various solutions here but none seem to work. I'm using zsh shell by default.
What i tried:
Went to my zprofile and included the following line:
if [ -f /etc/profile ]; then
PATH=""
source /etc/profile
fi
Didn't work.
Went to my profile and have the following code, still didn't work:
if [ -x /usr/libexec/path_helper ]; then
PATH=""
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
My bashrc file:
if [ -z "$PS1" ]; then
return
fi
PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
[ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM"
All the above files are located in /etc/ directory.
All my env variables are in .zprofile.
Thanks

Actually, this worked for me.
tmux set-option -g default-command zsh
i put above statement in my terminal

Related

terminal title not setting within screen

Currently, I'm setting terminal title within screen command, but the bash script gives me:
Cannot exec 'source /etc/profile && title.set root#test': No such file or directory
And I can run above command successful directly from the command line, here are my scripts:
/usr/local/bin/s
#!/bin/bash
if [ $1 ]
then
screen -D -R $1 -m "source /etc/profile && title.set `whoami`#$1"
else
screen -R
fi
/etc/profile
...
# Source global bash config
if test "$PS1" && test "$BASH" && test -z ${POSIXLY_CORRECT+x} && test -r /etc/bash.bashrc; then
. /etc/bash.bashrc
fi
function title.set() {
if [[ -z "$ORIG" ]]; then
ORIG=$PS1
fi
TITLE="\[\e]2;$*\a\]"
PS1=${ORIG}${TITLE}
}
# Termcap is outdated, old, and crusty, kill it.
unset TERMCAP
# Man is much better than us at figuring this out
unset MANPATH
...
So What's going wrong here?
The keyword source is a bash built-in command, i.e., something for which there is not necessarily an actual file to exec (another built-in command). You can only exec something that is a file — like bash, e.g., something like this:
screen -D -R $1 -m bash -c "source /etc/profile && title.set `whoami`#$1"

OSX terminal broken after trying to install cisco packet tracer

I tried to install cisco packet tracer on my mac. It was a sh script to install it. I ran it but not in su and it did some mess on my mac. After 1min i saw that my disk was full, since the script copied repertories everywhere.
Now, when i launch my terminal, the commands i recently installed (npm, brew, cordova...) are not recognized anymore, and there is not my user name at the beginning of the line, there is
-bash-3.2$
At every launch of the terminal, i get this error on the top of it :
Last login: Wed Jan 4 17:04:13 on ttys000
-bash: /etc/profile: line 1: syntax error near unexpected token `('
-bash: /etc/profile: line 1: `-e \n# System-wide .profile for sh(1)\n\nif [ -x /usr/libexec/path_helper ]; then\neval `/usr/libexec/path_helper -s`\nfi\n\nif [ "${BASH-no}" != "no" ]; then\n[ -r /etc/bashrc ] && . /etc/bashrc\nfi\nPT7HOME=/Users/myusername/Documents/pt'
I deleted the folder /Users/myusername/Documents/pt, but it seems that this is where the error is coming from. Thank you in advance for your help.
The error message implies that your /etc/profile, which by default looks like
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
was intended to be modified by adding a single line to the bottom
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
PT7HOME=/Users/myusername/Documents/pt
However, something went wrong, and in addition to adding a few extra characters to the beginning of the file, the indentation was removed and the newlines were converted to literal \n sequences, resulting in the contents becoming a single line, perhaps
-e \n# System-wide .profile for sh(1)\n\nif [ -x /usr/libexec/path_helper ]; then\neval `/usr/libexec/path_helper -s`\nfi\n\nif [ "${BASH-no}" != "no" ]; then\n[ -r /etc/bashrc ] && . /etc/bashrc\nfi\nPT7HOME=/Users/myusername/Documents/pt
Without further information, I would suggest that you could simply edit the file to look like the modified version above. However, #n.m.'s and #cdarke's suggestions should both be taken: restore from backup if possible, and contact user support to figure out what exactly may be wrong with the script.

mac: change PS1 in /etc/bashrc have no use

I use iTerm2 in mac .And I want to change the computer name.
I change the file /etc/bashrc
before:
if [ -z "$PS1" ]; then
return
fi
PS1='\h:\W \u\$ '
shopt -s checkwinsize
[ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM"
after
change the PS1
PS1='\#\W \$'
save , quit and restart the iTerm2
It useless...
Try creating a .bash_profile in your home directory and put your PS1 declaration there.

Where is Ruby getting added to my $PATH?

I’m using Mac Yosemite with bash shell. I had installed Ruby 2.2.1 but then wanted to upgrade it, so I installed Ruby 2.3.0. However, when I restart my terminal, my old Ruby installations in my PATH …
Daves-MacBook-Pro-2: davea$ echo $PATH
/Users/davea/.rvm/gems/ruby-2.2.1/bin:/Users/davea/.rvm/gems/ruby-2.2.1#global/bin:/Users/davea/.rvm/rubies/ruby-2.2.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin/:/opt/gradle-2.7/bin:/opt/apache-maven-3.3.3/bin:/Users/davea/.rvm/bin:/usr/local/mysql/bin
I can’t figure out how this part of my PATH is getting set. I have checked these files on my system
/etc/profile
/etc/bashrc
~/.profile
~/.bash_profile
But I don’t see references to Ruby 2.2.1 anywhere. Below are the files’ content. Are there any other files I should check to find references to the $PATH?
/etc/profile
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
JBOSS_HOME=/opt/wildfly-10.0.0.CR2
M2_HOME=/opt/apache-maven-3.3.3
CATALINA_HOME=/opt/apache-tomcat-6.0.44
GRADLE_HOME=/opt/gradle-2.7
PATH=$PATH:/usr/local/mysql/bin/:$GRADLE_HOME/bin:$M2_HOME/bin
/etc/bashrc
# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
return
fi
PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
printf '\e]7;%s\a' "$PWD_URL"
}
PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
fi
~/.profile
export JBOSS_HOME=$JBOSS_HOME
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
~/.bash_profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
RVM is setting up Ruby and related PATHS for you.
To get 2.3 run this
rvm --default use 2.3.0

A usage of dot in bash script

What does dot mean in line 8 of the following code snippet, from the source of /etc/profile in Mac OS X Mavericks terminal.
1 # System-wide .profile for sh(1)
2
3 if [ -x /usr/libexec/path_helper ]; then
4 eval `/usr/libexec/path_helper -s`
5 fi
6
7 if [ "${BASH-no}" != "no" ]; then
8 [ -r /etc/bashrc ] && . /etc/bashrc
9 fi
In bash, . is another way to spell source. So this line is the same as this:
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && source /etc/bashrc
fi
source interprets the file as if the content was included at the location of the source command. The difference with executing it is that it can set alias or define function or variables.
According to Bash Prompt HOWTO:
When a file is sourced (by typing either source filename or . filename
at the command line), the lines of code in the file are executed as if
they were printed at the command line. This is particularly useful
with complex prompts, to allow them to be stored in files and called
up by sourcing the file they are in.

Resources