LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Why there is a "command not found" prompt every time I open the Terminal? (https://www.linuxquestions.org/questions/linux-general-1/why-there-is-a-command-not-found-prompt-every-time-i-open-the-terminal-939595/)

cricketlong 04-13-2012 01:55 AM

Why there is a "command not found" prompt every time I open the Terminal?
 
the prompt looks like:
bash: $'\357\273\277#': commands not found.

[root@localhost ~]# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

pan64 04-13-2012 03:36 AM

looks like your prompt settings is not ok.
see http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html

onebuck 04-13-2012 09:47 AM

Member response
 
Hi,

This is a sample setup for both .bashrc & .bash_profile(which is used to source the .bashrc) for users home;
Code:

sample .bash_profile for proper sourcing with users home;
 ~$ cat .bash_profile
#.bash_profile file begins here
 # .bash_profile to source .bashrc
 #08-30-06 12:21
 # Source .bashrc
 if [ -f ~/.bashrc ]; then
         . ~/.bashrc
 fi                    #file ends here

Code:

sample .bashrc;

 :~$ cat .bashrc
 
 #.bashrc begins here
 #08-30-06 12:20
 
 # Add bin to path
 
 export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"
 
 #export PATH="$PATH:$HOME/bin"
 
 # Dynamic resizing
 shopt -s checkwinsize
 
 # Custom prompt
 #PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
 
#08-29-06 11:40
if [ `id -un` = root ]; then
   PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
  else
   PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
 #
 # Add color
 eval `dircolors -b`

 # User defined aliases
 alias cls='clear'
 alias clls='clear; ls'
 alias ll='ls -l'
 alias lsa='ls -A'
 alias lsg='ls | grep'
 alias lsp='ls -1 /var/log/packages/ > package-list'
 alias na='nano'
 alias web='links -g -download-dir ~/ www.google.com'
 
 #08-29-06 11:50
 
 #To clean up and cover your tracks once you log off
 #Depending on your version of BASH, you might have to use
 # the other form of this command
   trap "rm -f ~$LOGNAME/.bash_history" 0
 
#The older KSH-style form
#  trap 0 rm -f ~$LOGNAME/.bash_history

The .bashrc & .bash_profile are very useful for users!
HTH!

cricketlong 04-13-2012 02:54 PM

Thanks. but it seems that .bashrc is fine.
I edited my .bashrc:

1 #Cricket .bashrc
2
......

Then I open a new terminal or a new tab in terminal, it prompts:
bash: $'\357\273\277#Cricket': commands not found.

There is nothing to do with the rest content of my .bashrc.
But I don't still know where the first three letters come from.
weird...

onebuck 04-13-2012 03:29 PM

Hi,

Quote:

Originally Posted by cricketlong (Post 4651623)
the prompt looks like:
bash: $'\357\273\277#': commands not found.

[root@localhost ~]# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

Remove this form your ~.bashrc;
Code:

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

and place it in ~.bash_profile. So you will be sourcing .bashrc from the users ~.bash_profile.

cricketlong 04-17-2012 05:25 AM

Quote:

Originally Posted by onebuck (Post 4652089)
Hi,



Remove this form your ~.bashrc;
Code:

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

and place it in ~.bash_profile. So you will be sourcing .bashrc from the users ~.bash_profile.

thanks, but I am sure there is nothing to do with these three lines.

catkin 04-17-2012 07:26 AM

Is $PROMPT_COMMAND set?

cricketlong 04-19-2012 06:26 AM

Quote:

Originally Posted by catkin (Post 4654994)
Is $PROMPT_COMMAND set?

[root@localhost ~]# echo $PROMPT_COMMAND
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"

pan64 04-19-2012 07:56 AM

I tried the following:
PS1=`bla`, the result was:
bash: bla: command not found

so try to set PS1 to '>' or some simple string....

colucix 04-19-2012 09:01 AM

The sequence \357\273\277 is the octal representation of the Byte Order Mark of UTF-8 character encoding. Here is a comparative table:
Code:

Hex |      EF        BB        BF
Dec |      239      187      191
Oct |      357      273      277
Bin | 11101111  10111011  10111111

Most likely your terminal is not UTF-8 capable and it tries to interpret these three characters literally. Which terminal are you running? And which (Linux) OS is this? You have two possibilities:

1. make your terminal UTF-8 capable
2. convert all the UTF-8 files to another encoding, e.g. plain ASCII

Another question: what is the output of the following commands?
Code:

echo $PS1 | od -c
echo -e $PS1 | od -c


cricketlong 04-20-2012 04:18 AM

Quote:

Originally Posted by colucix (Post 4657350)
The sequence \357\273\277 is the octal representation of the Byte Order Mark of UTF-8 character encoding. Here is a comparative table:
Code:

Hex |      EF        BB        BF
Dec |      239      187      191
Oct |      357      273      277
Bin | 11101111  10111011  10111111

Most likely your terminal is not UTF-8 capable and it tries to interpret these three characters literally. Which terminal are you running? And which (Linux) OS is this? You have two possibilities:

1. make your terminal UTF-8 capable
2. convert all the UTF-8 files to another encoding, e.g. plain ASCII

Another question: what is the output of the following commands?
Code:

echo $PS1 | od -c
echo -e $PS1 | od -c


thanks, I am using gnome-terminal under Fedora 16.
How to make my terminal UTF-8 capable?

Here are the output:
[root@localhost ~]# echo $PS1 | od -c
0000000 [ \ u @ \ h \ W ] \ $ \n
0000015
[root@localhost ~]# echo -e $PS1 | od -c
0000000 [ \ u @ \ h \ W ] \ $ \n
0000015

colucix 04-20-2012 06:09 AM

Quote:

Originally Posted by cricketlong (Post 4658148)
thanks, I am using gnome-terminal under Fedora 16.
How to make my terminal UTF-8 capable?

It should be already enabled. What is the output of the following?
Code:

locale
I notice you run the commands as root. Does the problem happen as normal user or as root, as well? You should run all the suggested commands as the user whose prompt is
Code:

bash: $'\357\273\277#': commands not found.
Please, use CODE tags around the code you copy/paste from your terminal. To use CODE tags put [CODE] and [/CODE] before and after the code, respectively. Thank you.

catkin 04-20-2012 08:41 AM

Quote:

Originally Posted by cricketlong (Post 4657232)
[root@localhost ~]# echo $PROMPT_COMMAND
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"

That's a strange use of PROMPT_COMMAND. From the GNU bash reference:
Quote:

PROMPT_COMMAND
If set, the value is interpreted as a command to execute before the printing of each primary prompt ($PS1).
It looks as if somebody has set it on your system to provide the prompt.

What happens if you unset it and set a simple PS1 prompt as pan64 suggested:
Code:

unset PROMPT_COMMAND
export PS1='> '


colucix 04-20-2012 08:43 AM

Quote:

Originally Posted by catkin (Post 4658337)
That's a strange use of PROMPT_COMMAND.

Indeed. However, it is used by the gnome-terminal to set the window title! :)

cricketlong 04-28-2012 03:14 AM

Quote:

Originally Posted by colucix (Post 4658205)
It should be already enabled. What is the output of the following?
Code:

locale
I notice you run the commands as root. Does the problem happen as normal user or as root, as well? You should run all the suggested commands as the user whose prompt is
Code:

bash: $'\357\273\277#': commands not found.
Please, use CODE tags around the code you copy/paste from your terminal. To use CODE tags put [CODE] and [/CODE] before and after the code, respectively. Thank you.

Code:

[root@localhost JRDJ]# locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=

This error appears only when I login as root.


All times are GMT -5. The time now is 07:52 AM.