A usage of dot in bash script - bash

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.

Related

duplicate paths found in tmux mac

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

Wrong contents appearing in .bashrc and .bash_profile files in the ~/ directory instead of the expected user environment variables and values

I am currently in the ~/ directory in terminal on my Mac, and trying to configure the .bash_profile.
I am trying to issue the cat command to view its contents. The result is the following:
# The next line updates PATH for the Google Cloud SDK. if [ -f '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud. if [ -f '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc'; fi export PATH="/usr/local/opt/ncurses/bin:$PATH"
I receive the following when I try to view the .bashrc file:
if [ -f '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/path.bash.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc' ]; then . '/Users/iwill/Downloads/google-cloud-sdk/completion.bash.inc'; fi
Any ideas why am I not seeing the user environment variables as I should be ?

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.

Messed up "/etc/bash.bashrc" cannot edit it again [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I tried to export a PATH to /etc/bash.bashrc file, but I added some invalid identifiers. Now I am not able to access program such as ls, nano, vi, gedit from the terminal, and that's why couldn't correct the /etc/bash.bashrc file. How can I edit it in this situation? Thank you!
On my Ubuntu the nano and vi programs live in /usr/bin. So you might try
$ sudo /usr/bin/nano /etc/bash.bashrc
$ sudo /usr/bin/vi /etc/bash.bashrc
You can do one of two things:
1) Use full path of vi to edit /etc/bash.bashrc file:
/usr/bin/vi /etc/bash.bashrc
2) Correct the path on the command line then fix:
export PATH=...
vi /etc/bash.bashrc
$ cat /etc/bash.bashrc
# System-wide .bashrc file for interactive bash(1) shells.
# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, overwrite the one in /etc/profile)
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user#host:dir
#case "$TERM" in
#xterm*|rxvt*)
# PROMPT_COMMAND='echo -ne "\033]0;${USER}#${HOSTNAME}: ${PWD}\007"'
# ;;
#*)
# ;;
#esac
# enable bash completion in interactive shells
#if ! shopt -oq posix; then
# if [ -f /usr/share/bash-completion/bash_completion ]; then
# . /usr/share/bash-completion/bash_completion
# elif [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
# fi
#fi
# sudo hint
if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then
case " $(groups) " in *\ admin\ *)
if [ -x /usr/bin/sudo ]; then
cat <<-EOF
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
EOF
fi
esac
fi
# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
}
fi
You can specify a full path on the command line like
$ /usr/bin/nano /etc/bash.bashrc
That way you can pull up nano and edit it.
You could also attempt to run /bin/sh to get a "standard" shell.

Resources