If I run this in the terminal (Mac OSX):
vim dump.md -c 'vsplit poa.md' -c 'split one.md' -c ':wincmd h'
It works great (creates three windows with those files).
If I have it as part of a bash script, there's a problem. After doing what it's supposed to do, it leaves me with this in the vim status line:
1:dump.md 2:poa.md 3:one.md
1:dump.md 2:poa.md 3:one.md
Press ENTER or type command to continue
I have to press ENTER 6 times to clear the status line and return to editing (each ENTER outputs the above again).
Anyway around this?
Also, not sure if this is significant, but vim is aliased to mvim (MacVim).
EDIT
Here is the bash script, although I don't think it matters I've run the whole script separately before manually putting the vim dump.md... command it, and it works fine.
13
12 #!/bin/bash
11
10 cd ~/Dropbox/Journal/dumps/
9
8 LAST=`ls -tAF | grep '/$' | head -1`
7 NEW=dump-$(date +"%Y-%m-%d_%T")
6
5 mkdir $NEW
4 cd $NEW
3
2 cp ../$LAST/poa.md ./poa.md
1
14 vim dump.md -c 'vsplit poa.md' -c 'split one.md' -c ':wincmd h'
1
At first:
ls -al
And see just your file is existed...If your file is test make sure vim doesn't cread such files:
.test OR test~ OR something like these
Then :
vim file
Do your changes...
After that close it by saying:
:wq!
Then try to open it again...The problem should be solved
UPDATE
try this one:
ls -a | grep swp
if there was a file like : .script.swp or something like these you should remove them...
Your problem would be solved...You should see if your script it existed with .script.... and you should remove it...
If you can't find files start with . try to move all files(scripts) to another directory then work with them..and use :q! to quite and use :wq! to save and quite...
Can anybody explain what is wrong with my terminal:
$ echo $PATH
=/usr/local/bin
$ ls
-bash: ls: command not found
$ cd
-bash: find: command not found
Why won't these commands work? Help? Anyone?
I'm guessing your .bash_profile or .bashrc has a line that looks like
export PATH=/usr/local/bin
This is overwriting all the existing stuff that needs to be in your $PATH. You need to change this line to look like
export PATH=/usr/local/bin:$PATH
"ls" lives in "/bin" and "find" lives in "/usr/bin". You need to add these to your $PATH in your bash_profile or .bashrc.
Whenever I open my terminal on my mac I get this message, -bash: /usr/local/bin: is a directory
How do I remove this? As I find it annoying and unneeded.
There is probably a line trying to execute /usr/local/bin (which is a directory and not a executable) in either your ~/.bash_profile or your ~/.bashrc
If you want to view the contents of these files (as you asked above) you can type in your terminal after you open it:
cat ~/.bash_profile
and
cat ~/.bashrc
You can try to verify what lines mention /usr/local/bin by typing these commands:
cat ~/.bash_profile | grep "/usr/local/bin"
and
cat ~/.bashrc | grep "/usr/local/bin"
I've somehow managed to screw up bash while fiddling with the $PATH variable in my bash_profile (I think...). All I did, as far as I can remember, was add a directory to the $PATH variable. Please HELP!
Here's what I get when I cd into various directories
my-MacBook-Pro:~ myuser$ cd .rvm
-bash: dirname: command not found
-bash: find: command not found
my-MacBook-Pro:.rvm myuser$ cd
-bash: find: command not found
And here's what happens when I try to get into my .bash_profile to undo whatever it is that I did...
my-MacBook-Pro:~ myuser$ emacs .bash_profile
-bash: emacs: command not found
my-MacBook-Pro:~ myuser$ sudo emacs .bash_profile
-bash: sudo: command not found
Any help would be massively appreciated. I'm completely screwed until I can get bash working normally again!
/usr/bin/emacs .bash_profile or similar should work when the PATH is broken.
The $PATH variable tells the shell where to look for commands. If you just bypass that by telling it the full path, it should work. Try /usr/bin/emacs .bash_profile.
When you do a cd, you're getting a bunch of other things. Since you're using BASH there are are two possible issues:
You have PROMPT_COMMAND defined. Try to undefining it:
$ unset PROMPT_COMMAND
There's an alias of the cd command: This was quite common in Kornshell where you don't have the nice backslashed characters you could put into your prompt string. If you wanted your prompt to have the name of your directory in it.
You had to do something like this:
function _cd
{
logname="$(logname)"
hostname="$(hostname)"
directory="$1"
pattern="$2"
if [ "$pattern" ] #This is a substitution!
then
\cd "$directory" "$pattern"
elif [ "$directory" ]
then
\cd "$directory"
else
\cd
fi
directory=$PWD
shortName=${directory#$HOME}
if [ "$shortName" = "" ]
then
prompt="~$logname"
elif [ "$shortName" = "$directory" ]
then
prompt="$directory"
else
prompt="~$shortName"
fi
title="$logname#$hostname:$prompt"
PS1="$title
$ "
}
alias cd="_cd"
Ugly isn't it? You don't have to go through all of that for BASH, but this does work in BASH too, and I've seen places where this was done either out of ignorance of inertia.
Try this:
$ type cd
You'll either get
$type cd
cd is a shell builtin
or you'll get
$ type cd
cd is an alias for ....
As for your updating of $PATH, you probably forgot to put $PATH back in the new definition, or quotation marks because someone has a directory name with a space in it. Your PATH setting should look like this:
PATH="/my/directory:$PATH"
Some people say it should be:
PATH="$PATH:/my/directory"
I guess, that you have defined $PROMPT_COMMAND (maybe in .bashrc) in a way that uses dirname and find.
That would explain the behavior of cd.
The find command is by default in /usr/bin/find. Thus, you can use it to find the locations of your imprtant commands and reconstruct you path information.
How can I find out where an alias is defined on my system? I am referring to the kind of alias that is used within a Terminal session launched from Mac OS X (10.6.3).
For example, if I enter the alias command with no parameters at a Terminal command prompt, I get a list of aliases that I have set, for example:
alias mysql='/usr/local/mysql/bin/mysql'
However, I have searched all over my system using Spotlight and mdfind in various startup files and so far can not find where this alias has been defined. ( I did it a long time ago and didn't write down where I assigned the alias).
For OSX, this 2-step sequence worked well for me, in locating an alias I'd created long ago and couldn't locate in expected place (~/.zshrc).
cweekly:~ $ which la
la: aliased to ls -lAh
cweekly:~$ grep -r ' ls -lAh' ~
/Users/cweekly//.oh-my-zsh/lib/aliases.zsh:alias la='ls -lAh'
Aha! "Hiding" in ~/.oh-my-zsh/lib/aliases.zsh. I had poked around a bit in .oh-my-zsh but had overlooked lib/aliases.zsh.
you can just simply type in alias on the command prompt to see what aliases you have. Otherwise, you can do a find on the most common places where aliases are defined, eg
grep -RHi "alias" /etc /root
First use the following commands
List all functions
functions
List all aliases
alias
If you aren't finding the alias or function consider a more aggressive searching method
Bash version
bash -ixlc : 2>&1 | grep thingToSearchHere
Zsh version
zsh -ixc : 2>&1 | grep thingToSearchHere
Brief Explanation of Options
-i Force shell to be interactive.
-c Take the first argument as a command to execute
-x -- equivalent to --xtrace
-l Make bash act as if invoked as a login shell
Also in future these are the standard bash config files
/etc/profile
~/.bash_profile or ~/.bash_login or ~/.profile
~/.bash_logout
~/.bashrc
More info: http://www.heimhardt.com/htdocs/bashrcs.html
A bit late to the party, but I was having the same problem (trying to find where the "l." command was aliased in RHEL6), and ended up in a place not mentioned in the previous answers. It may not be found in all bash implementations, but if the /etc/profile.d/ directory exists, try grepping there for unexplained aliases. That's where I found:
[user#server ~]$ grep l\\. /etc/profile.d/*
/etc/profile.d/colorls.csh:alias l. 'ls -d .*'
/etc/profile.d/colorls.csh:alias l. 'ls -d .* --color=auto'
/etc/profile.d/colorls.sh: alias l.='ls -d .*' 2>/dev/null
/etc/profile.d/colorls.sh:alias l.='ls -d .* --color=auto' 2>/dev/null
The directory isn't mentioned in the bash manpage, and isn't properly part of where bash searches for profile/startup info, but in the case of RHEL you can see the calling code within /etc/profile:
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null 2>&1
fi
fi
done
Please do check custom installations/addons/plugins you have added, in addition to the .zshrc/.bashrc/.profile etc files
So for me: it was git aliased to 'g'.
$ which g
g: aliased to git
Then I ran the following command to list all aliases
$ alias
I found a whole lot of git related aliases that I knew I had not manually added.
This got me thinking about packages or configurations I had installed. And so went to the
.oh-my-zsh
directory. Here I ran the following command:
$ grep -r 'git' . |grep -i alias
And lo and behold, I found my alias in :
./plugins/git/git.plugin.zsh
I found the answer ( I had been staring at the correct file but missed the obvious ).
The aliases in my case are defined in the file ~/.bash_profile
Somehow this eluded me.
For more complex setups (e.g. when you're using a shell script framework like bash-it, oh-my-zsh or the likes) it's often useful to add 'alias mysql' at key positions in your scripts. This will help you figure out exactly when the alias is added.
e.g.:
echo "before sourcing .bash-it:"
alias mysql
. $HOME/.bash-it/bash-it.sh
echo "after sourcing bash:"
alias mysql
I think that maybe this is similar to what ghostdog74 meant however their command didn't work for me.
I would try something like this:
for i in `find . -type f`; do # find all files in/under current dir
echo "========"
echo $i # print file name
cat $i | grep "alias" # find if it has alias and if it does print the line containing it
done
If you wanted to be really fancy you could even add an if [[ grep -c "alias" ]] then <print file name>
The only reliable way of finding where the alias could have been defined is by analyzing the list of files opened by bash using dtruss.
If
$ csrutil status
System Integrity Protection status: enabled.
you won't be able to open bash and you may need a copy.
$ cp /bin/bash mybash
$ $ codesign --remove-signature mybash
and then use
sudo dtruss -t open ./mybash -ic exit 2>&1 | awk -F'"' '/^open/ {print substr($2, 0, length($2)-2)}'
to list all the files where the alias could have been defined, like
/dev/dtracehelper
/dev/tty
/usr/share/locale/en_CA.UTF-8/LC_MESSAGES/BASH.mo
/usr/share/locale/en_CA.utf8/LC_MESSAGES/BASH.mo
/usr/share/locale/en_CA/LC_MESSAGES/BASH.mo
/usr/share/locale/en.UTF-8/LC_MESSAGES/BASH.mo
/usr/share/locale/en.utf8/LC_MESSAGES/BASH.mo
/usr/share/locale/en/LC_MESSAGES/BASH.mo
/Users/user/.bashrc
/Users/user/.bash_aliases
/Users/user/.bash_history
...
Try: alias | grep name_of_alias
Ex.: alias | grep mysql
or, as already mentioned above
which name_of_alias
In my case, I use Oh My Zsh, so I put aliases definition in ~/.zshrc file.