I cannot get my .bash_profile aliases to work on my Mac OSX Terminal. I created a .bash_profile file in my ~/ directory, then wrote two lines:
echo bash profile has loaded
alias prof=“open ~/.bash_profile”
I saved and entered in Terminal command:
. ~/.bash_profile
Terminal displayed:
bash profile has loaded
-bash: alias: /Users/kennethlarose/.bash_profile”: not found
I've been reading up on alias profiles, and I believe my syntax is valid. I know the profile is sourcing because it displays the echo, but Terminal will show the same 'not found' message no matter what command I save in the alias. Does anybody know what else I can try?
Let's ask shellcheck!
In .bash_profile line 2:
alias prof=“open ~/.bash_profile”
^-- SC1015: This is a unicode double quote. Delete and retype it.
There's your problem. OS X has turned your double quotes into fancy slanted quotes that bash doesn't recognize. If you're programming, you may want to disable "smart quotes".
Related
Related Issue: How to change the terminal prompt to just current directory?
I have added export PS1="\w\$ " to my ~/.bash_profile, but the prompt for the command line just displays this:
\w$
It recognizes the backslash escape for the $ character, but not for the filepath. It does the same thing when I use a capital 'W'.
The problem was that my terminal is running zsh. I created ~/.zshrc and wrote the following code:
PROMPT="%/\$ "
I referred to this resource to find the appropriate characters for displaying the current file path: ZSH Prompt Expansion.
I am using macOS High Sierra and I am getting the following error when trying to install a script:
sh: Fusion.app/Contents/Public:/Users/<name>/.rvm/bin: No such file or directory
Apparently has something to do either with rvm or Fusion.app, which I don't have that app, what I have is VMWare Fusion.app.
VMWare changes your $PATH variable, but it does not do in .profile, or /etc/profile, neither the globals or locals bashrc or zshrc files.
It has its own file inside /etc/paths.d. The file is called com.vmware.fusion.public.
You need sudo rights to change the file:
$ sudo vim /etc/paths.d/com.vmware.fusion.public
The file is readonly and it has as content:
/Applications/VMware Fusion.app/Contents/Public
Notice there are not quotes around it, and the space character is not escaped. You need to add a \ after the VMWare and before the white space.
Final result:
/Applications/VMware\ Fusion.app/Contents/Public
Quit vim with :x!.
Open a new terminal window and run your command again, you should not have that error anymore.
With VMware Fusion rewriting /etc/paths.d/com.vmware.fusion.public on launch;
Adding this PATH find and replace line to my .bash_profile seems to be working:
export PATH=${PATH//VMware\ F/VMware\\ F}
This happens because some shell script (in this case perhaps rvm) is not following best practices, specifically:
Double quote to prevent globbing and word splitting
https://github.com/koalaman/shellcheck/wiki/SC2086
Changing /etc/paths.d/com.vmware.fusion.public as suggested in other answers could break all other places where this variable is wrapped in double quotes.
When I open my ~/.zshrc file and add alias homestead=“cd ~/Homestead”, I expect to be able to type homestead and be taken to the Homestead folder.
Instead I get the following error:
zsh: command not found: “cd
Even when I use single quotes, i.e. alias homestead='cd ~/Homestead' and run source ~/.zshrc I get the same error.
UPDATE: Also, when I run which homestead I get homestead: aliased to "cd
How can I fix this?
The answer was to open ~/.zshrc in Sublime Text as opposed to TextEdit and to check that the " were coming up as 042 in an octal dump.
You don't need to define this alias at all in zsh. Add the following to your .zshrc:
setopt autocd
cdpath+=(~)
The first allows you to treat a directory name as a command, which implicitly sets the working directory of the current shell to the named directory. The second specifies that if the current directory doesn't have a directory whose name is used with cd (or by itself with autocd set), then try to find it in a directory named in the cdpath parameter.
With these two, simply typing Homestead will first try to run a command named Homestead; failing that, it tries to cd to ./Homestead, and failing that, will finally succeed in cding to ~/Homestead.
The double quotes must be ASCII, not Unicode outside the ASCII range. Load the file in your editor, disable any automatic mangling of single quotes and double quotes. Then replace the funny quotes with ASCII quotes " (code decimal 34, hex 22, octal 042). Or type the command at a prompt, then cut & paste it in your editor. If all else fails, add the alias at the end of your .zshrc with
printf 'alias homestead="cd ~/homestead"' >> ~/.zshrc
Verify the result with octal dump,
od -bc .zshrc
The number above the quotes should appear as 042.
Maybe your locale settings is auto correcting a double quote " into a localized double quote “ as you posted. Since this is not recognized as a valid quote in shell, a simple white-space would break the string. So the actual alias is “cd.
As to why alias homestead='cd ~/Homestead' does not work, it seems you changed the alias in ~/.zshrc. From the which homestead result, it can be seen that alias homestead='cd ~/Homestead' does not really work. Maybe there is another line of alias homestead=“cd ~/Homestead” hidden in .zshrc after it.
Just saying that for me what fixed it was an error in the first alias in my list that had a question mark in it.
Just switched to Mac OS Catalina and ~/.bashrc to ~/.zshrc and I guess zsh doesn't support question marks.
Maybe it'll help someone coming here from Google search like I did.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I have been trying to alter the .bash_profile that is in my root directory, but have been running into some problems. I am on OS X, Yosemite, on a Macbook Pro. As I understand it, the .bash_profile file contains the script that is called automatically whenever the Terminal app is opened and the bash shell starts.
This is what I currently have written in that file:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
This works perfectly fine. However, I want to add an alias (right underneath the above two lines) as follows:
alias test='cd ..'
However, when I save this and start up the Terminal, I get the following message:
-bash: alias: ..": not found
Replacing the single quotes with double quotes doesn't help, nor does taking them away altogether. Curiously however, the following alias works:
alias c=clear
When I type c into the terminal, it clear the screen, as you would expect. However, if I instead entered this line with quotes in the bash profile as:
alias c='clear'
Then I will get the following whenever I enter c into the Terminal:
-bash: 'clear': command not found
Note that I do not get an error message on startup for this alias.
What am I doing wrong? Is there a setting I need to change somewhere to get aliases to work properly? I have seen previous examples of aliases and they simply do not work for me.
It looks like shell is not accessing your .bash_profile when logging via terminal.
.bash_profile is a config file of bash shell. When bash shell starting, shell will execute the commands in .bash_profile. But there are many kinds of shells, and different shells execute different config file.
Terminal is a software to receive user input, shell will execute commands.You can use cat /etc/shells to list acceptable shells. For example:
$ cat /etc/shells
/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
The default shell is bash shell on Mac OX. But if you have installed zsh, the default shell is zsh, when zsh shell starting, shell will find out the file named .zshrc, and execute the commands in .zshrc.
You can use echo $SHELL to determine the current shell:
$ echo $SHELL
/bin/bash
-> echo $SHELL
/bin/zsh
If your default shell is zsh, .bash_profile don't work. The config file of zsh is .zshrc. And I guess your problem is that your default shell is not bash shell. For example, if your default shell is zsh, you should config the .zshrc , just add
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
or other config to ~/.zshrc.
Then source ~/.zshrc, and the config will work immediately.
Wrapping the command with double quotation worked for me. I was trying with every possible way mentioned in this thread and none of them worked. Then I replaced single quote to double and that worked.
alias mysql_start="sudo /path/to/server/mysql.server start"
For me, it didn't work in the same terminal. I had to open a new one to get it work.
The killer for me was space and single quotes.
alias test="cd .." worked.
Don't put any spaces between alias_name=
User level 'system' files need to contain 'plain text'. How to set/configure this for your 'editor-of-choice' can vary (I don't use a Mac so I'm not much help with that.) Soo,
create your profile 'from the shell' by appending lines directly, i.e. remove the 'bad lines and then:
echo "some command string" >> ~/path/bash_profile
use 'vi' or 'vim' ## should be 'safe'
review your file via:
cat -v ~/path/bash_profle | more ## see any 'funny chars'? or
cat -ve ~/path/bash_profle | more ## see any 'funny chars'? or
or
vi ~/path/bash_profle # then set 'control codes' to 'on'
set list ## see any 'funny chars' for your 'quotes'?
What I realised is that Mac has option for smart quotes and dashes.
alias ..='cd ../' is different from alias ..=‘cd ../‘, where the former works but the latter doesn't.
You can run alias custom auto startup in ~/.bash_profile or ~/.alias_file... by paste file name alias in ~/.bashrc if you use bash or ~/.zshrc if you use zsh.
Ex:
if [ -s ~/.bash_profile ]; then
source ~/.bash_profile;
fi
I fixed this by editing my .bash_profile in vim or nano something about text edited messed it up unsure why.
I tried to edit in in notepad just using "open .bash_profile" however something about the symbols translated wrong. So you have to either "vim .bash_profile" or "nano .bash_profile"
Doing this corrected this problem for me.
Make sure that the alias commands are together in the .bash_profile too. That is what was wrong with mine.
Also, if you just type in alias in the terminal, it should list all the known alias commands, so if you don't see your command you know something is wrong.
If alias is not recognizing, first identify what shell you're using when you open up your terminal or commandlineprompt echo $SHELL. For me it's /bin/bash so i'll input my aliases in ~/.bash_profile
Take note, the file ~/.bash_profile can store both aliases to call out during a terminal session and autorun those same aliases upon opening up a terminal session. The example below would be to open up a file to edit by text via vim-software. You may change it other text-editors as you wish. You can see the difference by closure-method.
ALIAS CALLOUT (uses parenthesis)
alias editbp="vim ~/.bash_profile"
ALIAS AUTORUN (uses tilda)
alias editbp=`vim ~/.bash_profile`
Using iTerm2 with zsh and it isn't recognizing my aliases. Sometimes I have to work in an IDE and can't just easily vim something and the stupid people thought it a good idea to name their applications like MyReallyLongApplicationName.app and since .html files open by default in browsers, I have to:
open -a MyReallyLongApplicationName.app something.html
I have an alias in my .zshrc like:
alias ide="open -a MyReallyLongApplicationName.app"
But zsh won't recognize my aliases. I tried another one just to see if it was me but none of the aliases I create are recognized. Just get "zsh: command not found: ide" or whatever.
So I'm not sure what I'm doing wrong and I've been searching around all day trying to fix things in zsh and the like. As a note, I'm not a pro at Linux/Unix systems so if you're too technical and vague I probably won't understand what you're telling me.
Thanks!
if you do a very simple alias in zsh, does it work? open your .zshrc file, and add the following line:
alias ls='ls -GpF'
after adding that line, type this line in your Terminal:
source ~/.zshrc
tell us what happens. Also, just for shiggles, make sure you are using single quotes vs. double quotes, I have seen that make a difference in the past on different versions of shells/OS/whatnot.
Add "source ~/.bash_profile" to your ~/.zsh config file.
Put this line:
/source: 'source ~/.bash_profile' into ~/.zshrc
After saving changes in ~/.zshrc file, open a new shell window and execute the command in it.
Sometimes the simple solution is what we need...
Add "source ~/.bash_profile" to your ~/.zshrc config file
echo source ~/.bash_profile >> ~/.zshrc
I needed to manually add the alias to my zsh config file and then run the source command on it.
echo alias this='some command' >> ~/.zshrc
source ~/.zshrc
In my case issue was space b/w aliasName and equalTo. you should have to remove those space.
bad assignment
alias keu = 'k exec -it utils bash'
correct one
alias keu='k exec -it utils bash'
What I did, in this case, was created a separate file to store all my aliases. I found this way to be cleaner and easier maintained.
My aliases file is simply called aliases and within my .zshrc I have the following:
# Linking my aliases file
source ~/foldername/aliases
Make sure the double quotes are actual double quotes and not some other character which looks like double quotes.
I was editing ~/.zsh-aliases in OSX - TextEdit, which, when hitting the double quotes key substituted it for another special double quotes character, which is not what ZSH expects.
After editing the alias file with Sublime and replacing the old double quotes with actual double quotes everything runs just fine.
Hope this helps.
I had all my aliases on ~/.bash_profile, so i added at the last line on ~/.zshrc the following line: . ~/.bash_profile and it worked for me.
You should put alias at the end of ~/.zshrc file.
you can use below command to do that:
echo alias this='some command' >> ~/.zshrc
after that run
source ~/.zshrc
then, open a new terminal and execute the command in it.
I'm using both bash and zsh with one .bashrc, .bash_aliases and .zshrc file.
Put this in you .zshrc to load bash files:
# shortcut to refresh .zshrc
alias refz="source ~/.zshrc"
# Load bash files to zsh
test -f $HOME/.bashrc && . $HOME/.bashrc
test -f $HOME/.bash_aliases && . $HOME/.bash_aliases
If you have many bash aliases and functions you may will have some error messages like:
/proc/self/fd/13:12310: bad option: -t
caused by bash specific lines in.bash_aliases or .bashrc files
You can skip those problematic ones using:
if [ -n "$BASH" ] ;then
lines to ignore by zsh
fi
For example kubectl autocompletion
# To fix error massage .bashrc:16: command not found: shopt
# Check if bash is the current shell, if not, skip it
if [ -n "$BASH" ] ;then
# kubectl and bash completions
if [ -x "$(command -v kubectl)" ]; then
source <(kubectl completion bash)
complete -F __start_kubectl k
fi
if ! shopt -oq posix; then
if [ -f /etc/profile.d/bash_completion.sh ]; then
. /etc/profile.d/bash_completion.sh
fi
fi
fi
# Instead I need to put this line somewhere in my zshrc
# to have kubectl autocompletion replacing the skipped bash one:
plugins=(git git-flow brew history node npm kubectl)
# To fix error message .bash_aliases:4: parse error: condition expected: =
# Change these to this syntax to be used by zhs
# Not compatible with zsh:
if [ $HOSTNAME = "x1" ]; then
# Compatible with bash and zsh:
if [[ $HOSTNAME == "x1" ]]; then
I had a bad alias line that should have been obvious.
There is no error checking in these zsh custom scripts, so you may, like me, waste a couple of precious hours trying to find out why your custom aliases or functions are not loading in iTerm2.
I am using MacOS Ventura 13.1 and iTerm 2 v3.4, zsh 5.8.1.
I reloaded and using . ~/zshrc and followed a lot of the suggestions above.
I finally copied my list of aliases and function to the ~/.zshrc file.
Another ~/.zshrc gave me a bad pattern error.
The fix for my case was as follows.
In line with a Unicode string or something that is escaped and requires ' ' (single quotes), you must use the other quote character (double quotes) to encapsulate the alias sting.
In my case, I had entered.
alias fixitemerrow='printf '\e[?2004l''
The fix for this is:-
alias fixitemerrow=" printf '\e[?2004l' "
Do not add spaces in your alias assignment. This is here just for illustration.
Spaces would also require double encapsulation " ' ' ".
Need to create a profile for .zshrc and register the alias into it. (only if the profile isn't available)
cd ~
touch .zshrc && open .zshrc
add all the alias in .zshrc file
source ~/.zshrc
close and re-open terminal and run the alias.