LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   'cd' command increases size of shell propmt (https://www.linuxquestions.org/questions/linux-newbie-8/cd-command-increases-size-of-shell-propmt-831377/)

thelink123 09-10-2010 08:51 AM

'cd' command increases size of shell propmt
 
Hi LQ,

When i change the directory using 'cd', the length of my shell prompt keeps on increasing. To make it more clear kindly see below

Code:

$> cd MyWorks
$ Myworks> cd Shell
$ MyWorks /Shell>

How can i fix the size of the shell promptt like even if i change the directory the length of shell prompt should remain unchanged.

rcbrgs 09-10-2010 09:12 AM

You may remove the part of the shell prompt related to your current directory.

I assume you're using bash. So your prompt is regulated by the PS1 variable. You can check your PS1 variable with the command:

echo $PS1

It should be similar to this:

$ ~/Desktop >echo $PS1
$ \w >

You can simplify your prompt to never show the working directory, by exporting the PS1 variable with a new value:

export PS1="\$>"

Now your prompt will always be "$>" no matter what.

If you want to have the working directory, but truncated to a specific number of letters, you'll have to find something more fancy. I suggest you start reading "man bash" on the section "PROMPTING", and post your findings here. (You can also read that to understand in more detail the instructions I wrote above).

jmc1987 09-10-2010 09:12 AM

How come you are putting > cd?

you should just do it like this

$cd MyWorks
$cd Shell
and so on.

rcbrgs 09-10-2010 09:15 AM

Sorry, I thought from your previous post that your prompt included a ">", but now I see you don't.

I am not typing the ">", I had it displayed on the end of the prompt.

Without this, the commands I wrote should be:

$ ~/Desktop echo $PS1
$ \w

export PS1="\$ "

rcbrgs 09-10-2010 09:19 AM

$ ~/Desktop echo $PS1
$ \w
$ ~/Desktop export PS1="\$ "
$ echo $PS1
$
$ cd
$ cd /var/log/
$

As you can see, the prompt is always the same size. To know here you are, you should use the "pwd" command:

$ pwd
/var/log

thelink123 09-10-2010 09:52 AM

Quote:

Originally Posted by rcbrgs (Post 4093484)
You may remove the part of the shell prompt related to your current directory.

I assume you're using bash. So your prompt is regulated by the PS1 variable. You can check your PS1 variable with the command:

echo $PS1

It should be similar to this:

$ ~/Desktop >echo $PS1
$ \w >

You can simplify your prompt to never show the working directory, by exporting the PS1 variable with a new value:

export PS1="\$>"

Now your prompt will always be "$>" no matter what.

If you want to have the working directory, but truncated to a specific number of letters, you'll have to find something more fancy. I suggest you start reading "man bash" on the section "PROMPTING", and post your findings here. (You can also read that to understand in more detail the instructions I wrote above).

Thanks for the quick reply

dv502 09-10-2010 10:08 AM

@ thelink123

The changes to the PS1 variable is temporary. To make it permanent, you'll need to edit /etc/bashrc and look for the PS1 variable line. This change will affect everyone on the system when they open a terminal. But, if you're the only user on linux, it's no problem.

If you have others using linux, and you want the PS1 prompt to apply to you only and no one else, you'll need to edit or create a hidden file called .bashrc in your home directory and add the line you want. For example:

export PS1="$ "

I use this for my prompt, export PS1="% " in my bashrc file.
%

I saw this prompt from a unix or sun terminal

- Cheers

thelink123 09-11-2010 07:48 AM

@dv502

Thanks :) I found out the same solution you provided in net. I was just about to add that for this thread, when i saw your post.

Thanks,
thelink123

dv502 09-11-2010 09:57 AM

You're Welcome...


All times are GMT -5. The time now is 09:12 PM.