The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM
Simple to you not simple to me pattern matchin help aleks001 Shell Programming and Scripting 0 07-22-2007 11:06 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 02:29 PM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 01:03 PM
Very simple question about changing PS1 variable at startup! abidmalik UNIX for Dummies Questions & Answers 2 08-26-2002 02:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-01-2002
sancho5 sancho5 is offline
Registered User
  
 

Join Date: Jan 2002
Location: Utah, USA
Posts: 5
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
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 (permalink)  
Old 01-01-2002
sancho5 sancho5 is offline
Registered User
  
 

Join Date: Jan 2002
Location: Utah, USA
Posts: 5
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 (permalink)  
Old 01-03-2002
negative negative is offline
Registered User
  
 

Join Date: Jan 2002
Location: Bandung, Indonesia
Posts: 11
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 (permalink)  
Old 01-03-2002
sancho5 sancho5 is offline
Registered User
  
 

Join Date: Jan 2002
Location: Utah, USA
Posts: 5
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 (permalink)  
Old 01-03-2002
negative negative is offline
Registered User
  
 

Join Date: Jan 2002
Location: Bandung, Indonesia
Posts: 11
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 (permalink)  
Old 01-03-2002
sancho5 sancho5 is offline
Registered User
  
 

Join Date: Jan 2002
Location: Utah, USA
Posts: 5
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 (permalink)  
Old 01-03-2002
negative negative is offline
Registered User
  
 

Join Date: Jan 2002
Location: Bandung, Indonesia
Posts: 11
I'm using /bin/bash, but i believe it works in /bin/sh too,
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0