1

Every time I su from root to another user on a CentOS system, it displays:

bash: q: command not found"

before giving me the prompt.

How to fix this?

Should I comment line

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

from vi /etc/sudoers ?

(ps: solution in When I run "sudo su" I get --bash: command not found for everything did not work...)

  • 6
    Sounds like some shell initialization script has a stray q in it that the shell tries to run as a command. – DepressedDaniel Dec 22 '16 at 23:01
  • Like maybe /etc/profile or something. – DepressedDaniel Dec 22 '16 at 23:06
  • (i'm not very into linux know how) but there is no letter 'q' even on /etc/profile – 10000000 Dec 22 '16 at 23:13
  • 1
    First: Are you running bash? Try: echo "$SHELL $BASH $PATH" Post output in your question. Next: what user are you suing to: root?. Then, if actually using bash, try to find any q in either of this files ~/.bashrc ~/.profile (there are others, but lets start with those two), try: grep "q" ~/.bashrc profile. – sorontar Dec 22 '16 at 23:34
  • 1
    basically it gives the error when I ssh to the server already (on my local bash_profile I just have "alias srv2="ssh root@178.xxx.xxx.xx" so is not coming from the local). And also gives the error for any other user. And the output ssh to the server after adding set -x its in codeshare.io/aVDO62 – 10000000 Dec 23 '16 at 13:02
5

From your post of bash -x:

++ . /etc/bashrc
+++ '[' '\s-\v\$ ' ']'
+++ '[' -z '' ']'
+++ case $TERM in
+++ '[' -e /etc/sysconfig/bash-prompt-xterm ']'
+++ PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" \
    "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
+++ q
-bash: q: command not found

So, there is a line with the letter q inside /etc/.bashrc after the line that sets the variable PROMPT_COMMAND. As it seems to be some stray text you can erase it.

You should edit the /etc/.bashrc inside the computer you ssh'ed to.

  • I think you mean /etc/bashrc, not ~/.bashrc – icarus Dec 23 '16 at 18:20
  • @icarus And indeed, correct you are. Edited. Thanks. – sorontar Dec 23 '16 at 18:35
  • yep, just checked the '~/.bashrc' for all users and there is no 'q' , it is in '/etc/bashrc' - Everything working smoothly - thank you! – 10000000 Dec 23 '16 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.