Bashrc profile was badly edited - bash

For error I have pasted:
export PATH=[...existing PATH additions]:/home/alumno/firefox/
on ~/.bashrc and now I cant access to any command, even sudo, because terminal returns: command not found.
And when the terminal is opened gives a message:
bash: export: `additions]:/home/alumno/firefox/': not a valid identifier.
I need to edit bashrc somehow. Any help, please?

You can edit the file with : "/usr/bin/vi .bashrc"
Regards!

Use absolute path for the commands.
Instead of ls, you need to call /bin/ls or in your case, use /bin/vi ~/.bashrc.

Related

How do I properly set aliases in a bash script (Ubuntu 17.04)?

I have this script called menal in my ~/bin directory:
#!/bin/sh
alias mendir='cd ~/projects/myproject'
It has executable property and I expect that when I run it it sets an appropiate alias for cd command for the terminal session. But it doesn't. When I type $ menal in terminal it shows no error, but when I try $ mendir after that I get
No command 'mendir' found, did you mean:
Command 'menhir' from package 'menhir' (universe)
mendir: command not found
When I type
$ alias mendir='cd ~/projects/myproject'
$ mendir
in terminal, it works.
What am I doing wrong? Is it a script scope issue or something?
Yes, it's a scope problem. Calling it the following way won't produce the result you expect:
./bin/menal
If you want the alias to persist, use source:
source ./bin/menal
You can add it to your .bash_profile.
alias mendir='cd ~/projects/myproject'
then do source ~/.bash_profile
It should create the alias and also will work on every login.

How to edit corrupted bash profile

I exported a PATH that is incorrect in my bash profile, and I can no longer open it to edit it. Even worse, my terminal is basically completely broken because of this.
If I run vim ~/.bash_profile
I get the following errors:
-bash: vim: command not found
-bash: sed: command not found
If I try to use a command like ls I get:
-bash: ls: command not found
-bash: sed: command not found
How can I fix my bash profile if I can't even edit it?
Your terminal isn't broken, bash is just lost because it is using this broken PATH variable, which you have saved in ~/.bash_profile. So, when you reload (source) your configuration, bash is simply re-reading from the same broken PATH.
To fix it, you must either edit the configuration or replace the file.
In the meantime, you can restore (what is likely) your default PATH temporarily, for the current shell session, from the command-line: PATH="/bin:/sbin:/usr/local/bin:/usr/bin:/usr/sbin:"
Otherwise, you must include the full path to each command you enter (as commented above) since bash no longer knows which directories to look in for these programs (commands).
Try /usr/bin/vim ~/.bash_profile to open the file for editing.
If you'd like to instead remove the file, try: /bin/rm ~/.bash_profile But don't forget to replace it!
Once you've successfully, edited or replaced the file, you need to source it for it to be loaded with each new instance of bash: . ~/.bash_profile.
Also, it is better to place your configuration in the ~/.bashrc file, though this would not have prevented the same situation from happening.

Terminal commands can not be found OSX

A majority of terminal commands don't work, for example .
ls
sudo
vi
with the error -bash: ls: command not found my path is echo $PATH
“/Users/username/usr/local/bin I get the feeling that “ should not be there but not sure how edit it.
What should the path be and how do I get the path to stay the same?
You need to add more paths to your $PATH variable. Try running whereis ls and check where is the binary of the command.
You can add more paths like this: export PATH=$PATH:NEW_PATH
I had a similar experience recently where a lot of my terminal commands were not being found despite being clearly saved in my bash_profile. After lengthy process of elimination I realised that the issue was caused when I tried to export a new path. The error that I had made was putting a space in the command. So I had to change
export SOMETHING = /path/to/something.apk to
export SOMETHING=/path/to/something.apk
So I would recommend you check all your path declarations to ensure you don't have any white spaces. Also don't forget to source your bash_profile or what ever type of command line shell you use.

Basic command lines on Mac terminal not working

I changed the bash profile while trying to install mongodb and none of my command lines are working on terminal. I read online that I need to fix the $PATH but I can't even access it when none of my commands are working.
Help?
Mistakenly I also ran into same problem where to resolve this I had to reset my PATH variable to basic settings as below :
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin"
Once you set PATH variable now you can open the .bash_profile file in same terminal session only and make changes accordingly. This will resolve your problem.
Ok I found the answer from here:
"Open Terminal, and go to File (or Shell) -> New Command. Type in open -e .profile (or substitute some other file instead of .profile), and hit Run. That should open TextEdit with the file you want to fix; you can remove the offending lines there."
in my case i typed in nano .bash_profile and that allowed me to edit my bash profile and fix the issue.
can't use terminal from error in .bash_profile
Run this in terminal:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

-bash: sudo: command not found Mac OS X (EC2 CLI prob?)

Getting the error:
-bash: sudo: command not found
echo $PATH outputs PATH:EC2_HOME/bin
I'm running Mac OSX 10.8.3
That seems wrong even for a n00b like me.
How do I fix my $PATH and return my computer to it's former self?
As stated in the comments the right files to set up your $PATH variable are: ~/.profile or ~/.bash_profile
export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
In this way when you re-enter in the console your PATH will work fine.
You can add other directories to your $PATH as you like.
If you just copy and past that line in an active console you just set the PATH variable temporary, when you logout and login again you will loose your path, so add it in your ~/.bashrc file.
I'm not sure how you've managed to get into that state, though this article explains how you can set your path.
If it helps, the output from my echo $PATH is: -
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
go to shell
choose new command
put this : sudo vim .bash_profile
then put : export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH
This worked for me:
echo $PATH
Followed by:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"

Resources