bash: /home/x/.bash_profile: Permission denied. How to fix this issue? - linux

I am trying to open the bash_profile file but it gives the following result
~/.bash_profile
bash: /home/x/.bash_profile: Permission denied
After searching I found this solution on the internet
source ~/.bash_profile
But this command gives the following output
The program 'the' is currently not installed. You can install it by typing:
sudo apt install the
when I typed it gives this result
sudo apt install
[sudo] password for x:
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.
x#ubuntu:~$ source ~/.bash_profile
The program 'the' is currently not installed. You can install it by typing:
sudo apt install the
please help me how to fix it.
Thank you All.

For viewing the bash_profile:
cat ~/.bash_profile
For editing:
vi ~/.bash_profile
If you get a permission denied, use sudo before cat or vi commands.

Hello
And for only creating your own without editing it...
set -x && $(type -p touch) ${HOME}"/.bash_profile"; set +x
... if already exists then only the modification time is changing.
I wrote the simple command cryptic because set -x shows what going on and set +x exits the debug mode.

After the clarifications, let me tell you what is happening.
The ~/.bash_profile file is a configuration file for configuring user environments. The users can modify the default settings and add any extra configurations on it. In your case, the file is empty and it is throwing an error because inside the file you have the word "the".
You Linux Server is trying to run the command "the", so the reason for the error you are getting is that you have no execution privileges over it. I've never ever heard of a program called "the", but giving your error perhaps the program is there. If the program did not exist, you would have gotten "No such file or directory".
Replace the content of the .bash_profile with the minimum content you need for this kind of file:
$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export PATH=.:$PATH:$HOME/.local/bin:$HOME/bin

Related

.Deb package postinst file not appending data to ~/.bashrc

I have this very simple postinst file for a .Deb package:
#!/bin/sh
echo 'alias command_pandora="sudo /usr/local/bin/pandora"' >> ~/.bashrc
echo 'Pandora Storage Server Installation complete.'
When I run it I even get the 'Pandora Storage Server Installation complete.' message, but nothing is appended to ~/.bashrc; nevertheless when I run this command alone in the terminal:
echo 'alias command_pandora="sudo /usr/local/bin/pandora"' >> ~/.bashrc
It does work. I already tried modifying the file permisions for ~/.bashrc but still get the same result. I also tried running a separate script with the same content and running it and it also works, so it seems to be related to dpkg.
Why is the content not being appended?
The postinst script runs as root. Package installation is a system installation utility; it should absolutely not modify users' private files, including those of root.
Tangentially, defining an alias seems like the wrong solution to your problem. Generally, prefer functions or shell scripts over aliases.
If the tool requires privileged access through sudo, perhaps refactor it to run itself with sudo (maybe with a check to only do this when it is connected to a terminal, to prevent it from hanging when run unattended).
Or, simply, include /usr/bin/command_pandora in the package with the following contents:
#!/bin/sh
exec sudo /usr/local/bin/pandora "$#"
(Marginally, I suppose it could add something to /etc/skel/.bashrc but this will only create a new alias for users which are created after this change, or users whose .bashrc presciently run source /etc/skel/.bashrc. I don't think that's a good idea, either.)

How can I make executables in my `PATH` available to GNU Make if they need to be run with sudo?

Consider the following Makefile.
install:
sudo rpi-install.py /dev/ttyUSB0 foo.bin
Note that I have deliberately not hardcoded a path to rpi-install.py because it is not in the same location on other people's machines, but I expect it to be in the PATH of everyone who uses my code.
Unfortunately, when I type make install, I get the following output.
sudo rpi-install.py /dev/ttyUSB0 larson.bin
sudo: rpi-install.py: command not found
make: *** [install] Error 1
When I type the exact same command on my shell, it works exactly as expected.
Additionally, when I remove the sudo from the Makefile, it successfully finds the binary and gets a permission denied error due to lack of root privileges.
How can I allow make to discover the programs that are in my PATH when they must be run with sudo?
For the sake of reproducibility, assume that the following contents are in rpi-install.py, and that it lives in the directory $HOME/bin. Additionally assume that PATH includes $HOME/bin.
#!/usr/bin/env python
print "Hello World!"
There was a combination of two fixes that resolved this problem.
I needed to set PATH in .profile instead of .bashrc because the default shell /bin/sh used by make did not pick up the correct path from .bashrc.
I needed to set the environment for the sudo command inside the makefile explicitly to be the external PATH, based on this answer to this question.
sudo env "PATH=$(PATH)" rpi-install.py /dev/ttyUSB0 larson.bin

bash: __vte_prompt_command: command not found

bash: __vte_prompt_command: command not found
Whenever I open a terminal, I am greeted with this line. Also, this is printed each time I enter a command in the terminal.
I am a linux-noob, and would be happy to read up, if someone can point me to some resource, or hint at a possible solution. I tried google-ing, but was unable to turn up with any useful results.
I did not do anything specific just before this started popping up.
Thanks in advance :)
Additional Info:
The terminal I used is the default gnome-terminal
Fedora 20
It sounds like a program named VTE has set your bash environment variable PROMPT_COMMAND to invoke a function called __vte_prompt_command.
The PROMPT_COMMAND environment variable defines a command that is executed before every new prompt is displayed to the screen. It can be very annoying when this command produces unexpected output.
You can temporarily get rid of the annoying messages by entering this command in the terminal:
__vte_prompt_command() { true; }
This creates a dummy function that does nothing - you can confirm by looking at the output of this command:
type __vte_prompt_command
After applying the hack to my system I see this:
__vte_prompt_command is a function
__vte_prompt_command ()
{
true
}
However, this is an indication that VTE may not be installed properly and/or may be broken. You might want to try to reinstall VTE, if possible. I would not recommend putting this permanently into your ~/.bashrc file.
I am running Ubuntu 18.04 with the default gnome-terminal and ran into the same problem but wanted a definitive solution.
After trying the solutions suggested previously, I still had the message:
__vte_prompt_command: command not found
comming up after starting a new terminal and after each command terminated.
I searched for a file in for instance .bashrc, .profile that would be doing a source /etc/profile.d/vte-2.91.sh with no luck.
Than I remembered that a long time ago I added the following line in my ~/.bashrc:
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
in order to append command line histories to all opened terminals. I figured out that commenting it solved the problem.
#export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
than
$ source ~/.bashrc
Thought I would share this for anyone having the same problem.
You can disable the corresponding code by editing your ~/.bashrc by using sudo gedit ~/.bashrc, searching for the string "vte" with STRG+F and outcommenting the line with a #.
On my system, the line looked like this, I guess an old installation of Ubuntu Budgie put it there:
if [ $TILIX_ID ] || [ $VTE_VERSION ] ; then source /etc/profile.d/vte.sh; fi # Ubuntu Budgie END
And if it looks like this, the line in your terminal will not appear anymore:
#if [ $TILIX_ID ] || [ $VTE_VERSION ] ; then source /etc/profile.d/vte.sh; fi # Ubuntu Budgie END
For CentOS7 (64 bit):
Try installing using yum command.
sudo yum update -y
sudo yum install -y terminator
sudo yum install -y epel-release
sudo yum install -y terminator #again
Resart the command prompt terminal, This worked for me (:
Reference: http://bytefreaks.net/gnulinux/install-terminator-in-centos-7-64bit
set +v
I think you may somehow made: set -v (Prints shell input lines as they are read.)
so set i

Lost in Nodester Installation

I am trying to install my own version of Nodester. I have tried on Ubuntu 12.04 LTS and now with CentOS. I am not the most skilled Linux user (~2 months use) so I am at a loss at this point.
The instructions are located at https://github.com/nodester/nodester/wiki/Install-nodester#wiki-a. They ask you to "export paths (to make npm work)" with the lines necessary to accomplish this.
cd ~
echo -e "root = ~/.node_libraries\nmanroot = ~/local/share/man\nbinroot = ~/bin" > ~/.npmrc
echo -e "export PATH=3d9c7cfd35d3628e0aa233dec9ce9a44d2231afcquot;\${PATH}:~/bin3d9c7cfd35d3628e0aa233dec9ce9a44d2231afcquot;;" >> ~/.bashrc
source ~/.bashrc
I can accomplish all of this until I get to the source ~/.bashrc line. When I run that, I get the following:
[root#MYSERVER ~]# source ~/.bashrc
-bash: /root/.bashrc: line 13: syntax error near unexpected token ';;'
-bash: /root/.bashrc: line 13: 'export PATH=3d9c7cfd35d3628e0aa233dec9ce9a44d2231afcquot;${PATH}:~/bin3d9c7cfd35d3628e0aa233dec9ce9a44d2231afcquot;;
I have tried changing the quot; to " and that didn't help. I tried changing quot; to colons and that didn't help. I also removed that and it didn't help (I am sure many of you at this point are probably wondering why I would even try those things). Does anyone have any insight as to what I need to do to get this to run properly?
This looks more like a documentation error than your failing to understand anything. Created issue 409 for it on Github.
In the meantime, going back through the wiki page's history, I found the following which may help. It certainly looks more reasonable though I won't be able to confirm for some time.
Export paths (to make npm work):
> cd ~
> echo -e "root = ~/.node_libraries\nmanroot = ~/local/share/man\nbinroot = ~/bin" > ~/.npmrc
> echo -e "export PATH=\"\${PATH}:~/bin\";" >> ~/.bashrc
> source ~/.bashrc
From commit d71e66b4c96f04c13467ede5f6469d6d4dd17059

How to fix path variable in bash on Mac OSX Snow Leopard

This might be a noob question, but I need help. I screwed up my terminal by trying to alter my path variable using the following command:
$ sudo nano .profile
Before I did that, if I were to type:
$ echo $PATH
I would get: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
When I opened .profile in nano it told me that the file didn't exist. I figured that made sense, since I had never edited this file before. I proceeded to enter a path to a directory I was using for a php framework and saved the file.
After I saved the file, I noticed that none of my bash commands are working. Now I can't do anything from the terminal. I can't even edit .profile in nano because it says -bash: nano: command not found
I'm clearly new to working with the terminal. I feel completely lost. Please provide some guidance on how to restore the terminal to working condition.
Use absolute paths.
$ /usr/bin/sudo /usr/bin/nano .profile
If you add something to a path, never just do
PATH=/path/to/something
instead do
PATH=$PATH:/path/to/something
By the way, you shouldn't/don't have to use sudo to edit your own file, such as .profile. Use sudo only when you need to edit the file which doesn't to belong to your account.
I had the same problem!
The way I solved was writing the follow command in the terminal:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin:/usr/local/git/bin:/usr/X11/bin
Hope it can be useful for you

Resources