Alias command not found when running .bashrc - macos

I'm trying to do the simplest of shell aliases like I always use to do.
Here's my .bashrc (and same happened with ZSH and .zshrc) for instance :
alias ll=“ls -al”
alias edit_http=“open -e /etc/httpd/conf/httpd.conf”
and here's my $PATH variable :
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
When I open a new terminal window I get this :
-bash: alias: -al”: not found
-bash: alias: -e: not found
-bash: alias: /etc/httpd/conf/httpd.conf”: not found
Here's my ls -al result of .bashrc :
-rwxr-xr-x# 1 ed staff 78 Mar 17 03:55 .bashrc
Strangely I can type this into Terminal and it works :
alias ll="ls -al"
But not from within the .bashrc file.
Any suggestions ? I've checked so many forum entries and nothing worked so far.

It looks like something went wrong during copying the alias into your .bashrc.
You ended up with 'wrong' quotation mark. Replace “ with "and it should work. “ is unicode but you require ascii quotation marks. For testing you can use this .bashrc
# bashrc example
# won't work
alias ll=“ls -al”
# will work
alias la="ls -al"
And with this code you can verify your problem:
$ source .bashrc
-bash: alias: -al”: not found
$ ll
-bash: “ls: command not found
$ la
total 0
drwxr-xr-x 2 alneuman staff 68 Mar 17 12:18 .
drwxrwxrwx+ 70 alneuman staff 2380 Mar 17 12:18 ..
Have a look here at unix.stackexchange. Somebody had the same issue. Brave new unicode world ;)

Related

Linux bash command not found error

I created a couple of custom bash scripts that does some simple things like starting and stopping a PostgresSQL server. I have them stored in a specific directory of my choice.
Joes-MacBook-Pro:scripts joe$ l
total 24
-rwxr-xr-x 1 joe staff 124B Apr 18 21:22 pgstart
-rwxr-xr-x 1 joe staff 114B Apr 18 21:23 pgstatus
-rwxr-xr-x 1 joe staff 123B Apr 18 21:22 pgstop
Joes-MacBook-Pro:scripts joe$ pwd
/Users/joe/Softwares/scripts
I have even referenced these scripts in my .bash_profile as:
# Custom Scripts
export SCRIPTS_HOME=/Users/joe/Softwares/scripts
Now when I tried to use it as:
Joes-MacBook-Pro:~ postgres$ pgstart
-bash: pgstart: command not found
Should I place this script in the /bin/ directory on my Mac? Any clues?
I am no Mac-Expert, but based on linux, it should suffice to do the following in your .bash_profile:
export SCRIPTS_HOME=/Users/joe/Softwares/scripts
export PATH=$PATH:$SCRIPTS_HOME
You could omit the first line, and replace it accordingly.
Don't forget to restart your terminal, or to source your .bash_profile
Add this to your ~/.bash_profile:
PATH=$PATH:/Users/joe/Softwares/scripts
Restart Terminal and it will work.
run source ~/.bash_profile to engage the export.
However, prior to that add: PATH=$PATH:$SCRIPTS_HOME to your bash_profile so your executable can be found via command line.

Sourcetree: A .sh script launched by Sourcetree dosen't know environment variables from ~/.bash_profile

Sourcetree allows us to launch a .sh script, which is called Custom action. I am going to register a .sh file to open file with Sublime text. Before doing it, I did a test and found something is weird. the owner of Sourcetree launcher is hello and the owner of Bash shell is also hello like:
choegyutaes-MacBook-Pro:MacOS hello$ pwd
/Applications/SourceTree.app/Contents/MacOS
choegyutaes-MacBook-Pro:MacOS hello$ ls -al
total 6752
drwxr-xr-x# 3 hello admin 102 Feb 4 2015 .
drwxr-xr-x# 10 hello admin 340 Aug 9 00:46 ..
-rwxr-xr-x# 1 hello admin 3456064 Feb 4 2015 SourceTree
But Sourcetree script launcher does not have the exported PATH from ~/.bash_profile.
choegyutaes-MacBook-Pro:scripts hello$ cat ~/.bash_profile
#MAVEN
export M2_HOME=/usr/bin/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
#Mysql
export MYSQL=/usr/local/mysql/bin
export PATH=$MYSQL:$PATH
#bash history timestamp
export HISTTIMEFORMAT="%d/%m/%y %T "
#Sublime text
export SUBLIME=/Applications/Sublime\ Text.app/Contents/SharedSupport/bin
export PATH=$SUBLIME:$PATH
my shell script (sublime.sh)
#!/bin/bash
whoami
echo $PATH
sleep 3
lanuch script from Bash shell (iTerm)
choegyutaes-MacBook-Pro:scripts hello$ ./sublime.sh
hello
/Applications/Sublime Text.app/Contents/SharedSupport/bin:/usr/local/mysql/bin:/usr/bin/apache-maven-3.3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
launch script from Sourcetree.
as yon can see, the result of echo $PATH is different, but the result of whoami is the same. I think this would not a problem with Sourcetree. It occurs from my unfamiliarance with *nix system and environment variable. Why does not Sourcetree script launcher know the path to Sublime text?
.bash_profile is just for running a bash shell in a terminal.
You are probably running SourceTree from a shortcut or menu.
If you run SourceTree from your bash prompt you should find that it picks up the environment set and exported by .bash_profile.
Assuming that's it, then you need your short-cut or menu to have the same - I don't know OS-X - but there must be some means of setting the environment for an entire user context (i.e. for any process started under a user session, graphical from a menu, or a bash shell, or whatever.)

Executing MATLAB from Bash

I've been trying to work on opening/executing MATLAB from bash (I'm using Terminal, specifically). However, despite numerous attempts at troubleshooting, I have been unable to do it.
Running the "matlab" command gives me the error:
-bash: matlab: command not found
A cursory Google search suggested it could be an issue of my local bin, but my bin looks like:
/usr/local/bin:
total used in directory 16 available 208047788
drwxr-xr-x 4 alifarhat wheel 136 Jul 22 11:30 .
drwxr-xr-x 3 alifarhat wheel 102 Jan 22 01:56 ..
lrwxr-xr-x 1 alifarhat wheel 29 Jul 22 11:30 matlab -> /usr/local/matlab6/bin/matlab
lrwxr-xr-x 1 alifarhat wheel 26 Jul 22 11:30 mex -> /usr/local/matlab6/bin/mex
Which seems to indicate that matlab is talking to the bin.
If it helps, when I cd into /usr/local and then ls, the only directory/item in there at all is "bin". Could this have something to do with it? How can I fix it if it does?
It seems like PATH issues. Is /usr/local/bin in your $PATH?
Try
~$ echo $PATH
What do you see?
If /usr/local/bin is not part of your $PATH you can add it:
~$ export PATH=/usr/local/bin:$PATH
Then try and run matlab from shell
EDIT:
Based on these comments it seems like matlab executable is not located at /usr/local/matlab6/bin. Therefore, you can either
Add /Applications/MATLAB_R2014a.app/bin/ to path:
~$ export PATH=/Applications/MATLAB_R2014a.app/bin:$PATH
or
Replace the broken symbolic links in /usr/local/bin (you might need root privileges for this). See this thread for more details.
Once you are in the correct directory, you should execute the command:
./matlab
instead of just typing matlab.

“export: command not found [duplicate]

This question already has an answer here:
How to restore .bash_profile on a mac? None of my unix terminal are working [closed]
(1 answer)
Closed 2 years ago.
When I open terminal on my mac it shows
Last login: Sun Mar 15 22:12:02 on ttys000
-bash: “export: command not found
-bash: “export: command not found
-bash: “export: command not found
-bash: “export: command not found
(My echo $PATH)
MacBook-Air-Tim:~ timreznik$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/timreznik/bin:/usr/local/bin
MacBook-Air-Tim:~ timreznik$
I have already tried to edit my .bash_profile to
# general path munging
PATH=${PATH}:~/bin
PATH=${PATH}:/usr/local/bin
but it still keep showing me “export: command not found when I launch terminal...
P.S. all commands seems to work but my inner perfectionist is screaming!
First, export is a shell builtin:
$ type export
export is a shell builtin
This means that PATH is irrelevant.
Second, the error message makes clear that the script is attempting to run the command “export. There is no such command:
$ “export
bash: $'\342\200\234export': command not found
The solution is to remove the spurious character from before the string export.
This misspelled command is in one of the shell's initialization files. These would include: ~/.bashrc, /etc/bash.bashrc, ~/.bash_profile, ~/.bash_login, ~/.profile, and any files they include.
Alternatively, the following commands will tell you which files and which lines in those files have the misspelled export command:
PS4='+ $BASH_SOURCE:$LINENO:' BASH_XTRACEFD=7 bash -xlic "" 7>trace.out
grep '“export' trace.out
For details on how the above works, see this post.
I had a similar problem, the culprit was non-breaking space between export and the name of the variable.
To resolve the issue, just replace it with a regular space character.
Details:
I had the following in .bash_profile:
export a=foo
When I start new terminal, I would get
-bash: export a=foo: command not found
If we run xxd on the file, however, we can plainly see the problem (dots are non-printable characters:
$ cat .bash_profile | head -n1 | xxd
00000000: 6578 706f 7274 c2a0 613d 666f 6f export..a=foo
Byte sequence c2a0 stands for non-breaking space

Unable to successfully execute some commands in Cygwin

I installed Cygwin64 in my 64-bit Windows 7 machine. The following commands failed executing, however, by displaying the error messages below. Could you help providing a resolution please?
$ ll
-bash: ll: command not found
$ clear
-bash: clear: command not found
However, the command ls -l worked...
$ ls -l
total 0
Also i tried by un-commenting the following line in .bashrc file in my home dir -
# alias ll='ls -l'
But it didn't help either!
After you uncomment the alias, you should start a new Cygwin shell for it to take effect. The .bashrc file is actually a script that is sourced when bash starts.
clear is not a Cygwin (Unix) command. Just use Ctrl-L instead.

Resources