simple SH variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple SH variable
# 1  
Old 01-01-2002
simple SH variable

Greetz all,
I'm using OBSD 2.9 with /bin/sh as my shell. I want to modify the SH prompt to reflect my current working directory.
I'm new to shell programming, so pardon if I'm going about things wrong Smilie
I thought I'd be able to do it with the following line:
Code:
PS1="`pwd`# "

but of course, that leaves the prompt as my home directory when I log in and remains so even when I change directories. Can someone point me to the right way to have my SH prompt update the CWD everytime I CD into a new one?
# 2  
Old 01-01-2002
sorry for the quirkiness, but I should revise this question.

How does one set the prompt to read as follows?

<username>@<hostname>:<current_working_directory>#

for instance,
Code:
user@host:/user$

I would also allow the shell to show a hash (#) when root is logged in and a $ when a regular user logs in.

I thought I had it figured out before, but I didn't.
# 3  
Old 01-03-2002
Hi,

Hope this would help you.



Try to set the PS1 in ~/.shrc or you can type it (not automatic).

-----------------------

PS1=$'\\u@\\h:\\w\\$ '

-----------------------

should be working, and it will show you (for example):

-----------------------

sh-2.05# PS1=$'\\u@\\h:\\w\\$ '

root@negative:~# cd data

root@negative:~/data#

-----------------------
# 4  
Old 01-03-2002
no go.
when I enter that in (actually in my .profile file in ~), the prompt comes out reading:

\u@\h:\w$

not correct, of course.

What I have entered in the variable as follows:

PS1='\\u@\\h:\\w:$ '
export PS1

and also exacltly as you had shown in your reply.
Is it possible it's a different systax for Bourne used under OpenBSD?
# 5  
Old 01-03-2002
Im using OpenBSD and i put a "nice" Prompt:
----
PS1='\[\e[1;30m\][\[\e[0;35m\]\t\[\e[1;30m\]]\[\e[1;36m\]\u\[\e[1;30m\]@\[\e[0;36m\]\h\[\e[1;30m\]:\[\e[0;37m\]\w\[\e[1;30m\]\$\[\e[0;37m\] '
----

just for not getting bored with BLACK & WHITE prompt :)
# 6  
Old 01-03-2002
eh.. I have to ask, which shell are you using? I am using /bin/sh and even copying the variable as you set it ( PS1='\[\e[1;30m\][\[\e[0;35m\]\t\[\e[1;30m\]]\[\e[1;36m\]\u\[\e[1;30m\]@\[\e[0;36m\]\h\[\e[1;30m\]:\[\e[0;37m\]\w\[\e[1;30m\]\$\[0;37m\]' )
only makes my command... exactly that.
can someone refer a tutorial that goes over this?
# 7  
Old 01-03-2002
I'm using /bin/bash, but i believe it works in /bin/sh too,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

A simple variable frequency sinewave audio generator.

Hi all... Well I have not been inactive but working out how to make OSX 10.14.x command line audio player have a variable sample rate. This is a back door as afplay does not have a sample rate flag unlike aplay for ALSA, in Linux flavours. This is a DEMO only but a derivative of it will... (2 Replies)
Discussion started by: wisecracker
2 Replies

2. Shell Programming and Scripting

Simple Variable substitution in ksh not working

Hi Gurus, Not able to catch what's going wrong here. I just want to get output as "tree". server:/mk/app/nexapp $ echo $SHELL /usr/bin/ksh server:/mk/app/nexapp $ export db_name1="tree" server:/mk/app/nexapp $ export i=1 1st try: server:/mk/app/nexapp $ echo $(db_name$i) ksh: db_name1: ... (3 Replies)
Discussion started by: mukesh.lalwani
3 Replies

3. Shell Programming and Scripting

A simple variable subst is not working

Hi what i want: listing files in a special range ls -lrt 20120601{05..06}* ... -rw-rw-r-- 1 imp imp 279 1. Jun 07:51 201206010550 -rw-rw-r-- 1 imp imp 279 1. Jun 07:01 201206010600 -rw-rw-r-- 1 imp imp 279 1. Jun 07:11 201206010610 -rw-rw-r-- 1 imp imp 279 1. Jun 07:21... (1 Reply)
Discussion started by: IMPe
1 Replies

4. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

5. Shell Programming and Scripting

"Simple" echo/reading variable question...

Hello, I have a simple(I think) question! Although simple, I have been unable to resolve it, so I hope someone can help! OK, here it is: 1)I have an awk script that prints something, such as: awk '{print $2}' a > x so x might hold the value of say '10' 2)Now, I just want to check to see if... (4 Replies)
Discussion started by: astropi
4 Replies

6. Shell Programming and Scripting

Simple sed variable substitution

Give the code: set line = 2 set year = `sed -n '2p' file while ($line < 500) echo $line > f.txt @ line = $line + 1 end How do I utilize the variable $line in the code instead of the number 2. I'm using this in a while loop and counter. I've tried quoting it, double/single... (1 Reply)
Discussion started by: wxornot
1 Replies

7. Shell Programming and Scripting

simple assigning variable question

I know many will probably say go read some tutorials...I would like to say that I am. However, I need to know this for work and it needs to be done soon. In my script I have a while loop that reads a .tbl file of 4 columns and assigns them to variables a, b, c, d. Once in the loop i do ... (10 Replies)
Discussion started by: questionasker
10 Replies

8. Shell Programming and Scripting

Simple script to return environment variable

HI , In the below script I am trying to return the value of the environment variable TIBCO_HOME to the caller #! /usr/bin/csh set VAR_NAME=$1 echo VAR_NAME On the aix console.. set to setenv TIBCO_HOME /app/tibco When I execute the script... myscript.sh TIBCO_HOME, the script... (5 Replies)
Discussion started by: bce_groups
5 Replies

9. Shell Programming and Scripting

Help with simple variable

I am working with AIX ksh I may have an output like one of the following (I am acuatlly using "ps eww <pid>" in a script and would like to assign one of the varable to a varable in my script): example 1: a=1 b=2 c=3 d=4 e=5 f=6 g=8 or example 2: e=5 d=3 b=1 a=2 c=4 or example 3: 5=a 4=b 3=c... (4 Replies)
Discussion started by: 2dumb
4 Replies

10. UNIX for Dummies Questions & Answers

Very simple question about changing PS1 variable at startup!

Hello there ! I am new in this Unix world and just start learning Unix. I have very simple question about changing PS1 variable (Shell Prompt) i have local.profile file in my working directory, i open in vi edit mode and add this line PS1="Hello:>" and i save that file. I disconnected from... (2 Replies)
Discussion started by: abidmalik
2 Replies
Login or Register to Ask a Question