PS1 value in shells

PS1 value in shells

Post by Pauli » Tue, 07 Jun 2005 20:44:25



Hi all


which I can see is set by my PS1 prompt.

When I issue the 'sh' command my prompt becomes sh-2.05b$

I would like to keep my normal prompt, so tried exporting the PS1 variable
but no luck, all I now see is the value of my original PS1 variable -

I'm pretty new to Unix and am obviously missing something pretty
fundamental, any assistance appreciated.

Cheers, Paulie

 
 
 

PS1 value in shells

Post by Thorsten Kamp » Tue, 07 Jun 2005 21:55:24


* Paulie (2005-06-06 12:44 +0100)

Quote:> In my shell (zsh)

Good girl/boy ;-)


> which I can see is set by my PS1 prompt.

or $PROMPT

Quote:> When I issue the 'sh' command my prompt becomes sh-2.05b$

it's in fact bash (an old version) in sh compatibility mode.

> I would like to keep my normal prompt, so tried exporting the PS1 variable
> but no luck, all I now see is the value of my original PS1 variable -


As far as I know sh doesn't have the advanced abilities of the modern
shells to configure your prompt.

But why do you actually run sh in interactive mode? Some people run
int for scripting - but using it interactively doesn't make sense as
it's outdated for many years.

Thorsten

 
 
 

PS1 value in shells

Post by Sven Maschec » Tue, 07 Jun 2005 22:14:54



> [...] bash (an old version) in sh compatibility mode.
> [...] using it interactively doesn't make sense as it's outdated
> for many years.

You're confusing the traditional Bourne shell with the
"posix mode + historical startup" of bash: INVOCATION in bash(1).
 
 
 

PS1 value in shells

Post by Thorsten Kamp » Tue, 07 Jun 2005 22:54:28


* Sven Mascheck (2005-06-06 14:14 +0100)


>> [...] bash (an old version) in sh compatibility mode.
>> [...] using it interactively doesn't make sense as it's outdated
>> for many years.

> You're confusing the traditional Bourne shell with the
> "posix mode + historical startup" of bash: INVOCATION in bash(1).

I don't think I'm confusing anything.


(even if "sh" is just a symlink to bash).

This has nothing to do with the fact that bash doesn't read
~/.bash_profile.

And runnig sh interactively still makes no sense because you're
castrating yourself compared to the features that bash has.

Thorsten

 
 
 

PS1 value in shells

Post by Sven Maschec » Wed, 08 Jun 2005 01:22:33



>>> [...] bash (an old version) in sh compatibility mode.
>>> [...] using it interactively doesn't make sense as it's
>>> outdated for many years.

>> You're confusing the traditional Bourne shell with the
>> "posix mode + historical startup" of bash: INVOCATION in bash(1).

> I don't think I'm confusing anything.

even better, you haven't tried:


> (even if "sh" is just a symlink to bash).

   $ sh
   sh-2.05b$ set -o|grep posix
   posix           on


Quote:> And runnig sh interactively still makes no sense because you're
> castrating yourself compared to the features that bash has.

... a double confusion:

- bash is not castrated in posix mode,
  but according to the manual, posix mode means:
     "Change the behavior of bash where the default operation differs
      from the POSIX 1003.2 standard to match the standard"
  (that is, still providing all other bash features)

- POSIX(.2 / SUSv3) is a current standard.
  Your "outdated for many years", "castrating yourself" and
  notion of a plain "sh" usually is (at best) said confusion
  of traditional Bourne shell, POSIX(/Korn) shell and bash
  or bad advocacy without substance
  or trolling, upon which i would leave this thread.

--
posix shell <http://www.opengroup.org/onlinepubs/009695399/utilities/sh.html>
bourne shell <http://www.in-ulm.de/~mascheck/bourne/>

 
 
 

PS1 value in shells

Post by Bill Marcu » Wed, 08 Jun 2005 03:03:45


On Mon, 6 Jun 2005 12:44:25 +0100, Paulie


> Hi all


> which I can see is set by my PS1 prompt.

> When I issue the 'sh' command my prompt becomes sh-2.05b$

> I would like to keep my normal prompt, so tried exporting the PS1 variable
> but no luck, all I now see is the value of my original PS1 variable -

> I'm pretty new to Unix and am obviously missing something pretty
> fundamental, any assistance appreciated.

If you need to go from zsh to sh, you might write an alias or function
that sets PS1 (read the man page; every shell has its own bells and
whistles for prompting) and starts sh.

--
Depend on the rabbit's foot if you will, but remember, it didn't help
the rabbit.
                -- R.E. Shay

 
 
 

PS1 value in shells

Post by Thorsten Kamp » Thu, 09 Jun 2005 00:39:47


* Sven Mascheck (2005-06-06 17:22 +0100)


>>>> [...] bash (an old version) in sh compatibility mode.
>>>> [...] using it interactively doesn't make sense as it's
>>>> outdated for many years.

>>> You're confusing the traditional Bourne shell with the
>>> "posix mode + historical startup" of bash: INVOCATION in bash(1).

>> I don't think I'm confusing anything.

> even better, you haven't tried:


>> (even if "sh" is just a symlink to bash).

>    $ sh
>    sh-2.05b$ set -o|grep posix
>    posix           on


>> And runnig sh interactively still makes no sense because you're
>> castrating yourself compared to the features that bash has.

> ... a double confusion:

> - bash is not castrated in posix mode,
>   but according to the manual, posix mode means:
>      "Change the behavior of bash where the default operation differs
>       from the POSIX 1003.2 standard to match the standard"
>   (that is, still providing all other bash features)

> - POSIX(.2 / SUSv3) is a current standard.

So invoking bash as "sh" is just a "shortcut" for "conform to POSIX
standard"? Well, that's strange. Compare to zsh: "Zsh tries to emulate
sh or ksh when it is invoked as sh or ksh respectively;"

Quote:>   Your "outdated for many years", "castrating yourself" and
>   notion of a plain "sh" usually is (at best) said confusion
>   of traditional Bourne shell, POSIX(/Korn) shell and bash
>   or bad advocacy without substance

Is the Bourne Shell actively developed? Does it have the many new
interactive features of modern shells like bash or zsh? Does it have
features for scripting like modern shells (arrays, etc.)?

Quoting the page you mention in your signature (bourne shell
<http://www.in-ulm.de/~mascheck/bourne/>):

"The Bourne shell would probably be in much wider interactive use
today, if it provided line editing (and a history mechanism)"

I'd call a shell without line editing or history mechanism "castrated"
or "functionality reduced" if you prefer that. Amen.

Quote:>   or trolling [...]

Blubberdiblubb. One million dollar to the man who can reply in a
controversial thread without using this brainfart named
"troll/trolling".
 
 
 

PS1 value in shells

Post by Sven Maschec » Thu, 09 Jun 2005 01:44:19



> So invoking bash as "sh" is just a "shortcut" for
> "conform to POSIX standard"?

Well, you don't believe me but refuse to read bash(1).

Quote:> Is the Bourne Shell actively developed? Does it have the many new
> interactive features of modern shells like bash or zsh? Does it have
> features for scripting like modern shells (arrays, etc.)?

POSIX "sh" != Bourne Shell "sh"

(unwilling to play such games, EOD for me)

 
 
 

PS1 value in shells

Post by Thorsten Kamp » Thu, 09 Jun 2005 02:04:59


* Sven Mascheck (2005-06-07 17:44 +0100)


>> So invoking bash as "sh" is just a "shortcut" for
>> "conform to POSIX standard"?

> Well, you don't believe me but refuse to read bash(1).

I read it but I didn't understand it - or only at the fifth or sixth
time reading it.

Quote:>> Is the Bourne Shell actively developed? Does it have the many new
>> interactive features of modern shells like bash or zsh? Does it have
>> features for scripting like modern shells (arrays, etc.)?

> POSIX "sh" != Bourne Shell "sh"

Obviously. Confusingly. At least in bash where "sh" means "behave
POSIX correct" - contrary to zsh where "sh" means "emulate sh (Bourne
shell).

But I'm still convinced: there are no good reasons to run Bourne Shell
sh interactively. (While there may be good reasons to make a shell
conform strictly "POSIX correct").

Quote:> (unwilling to play such games, EOD for me)

There are no games here - except in your fantasy. We just have
different opinions.

Thorsten

 
 
 

PS1 value in shells

Post by Andrew Smallsha » Thu, 09 Jun 2005 03:02:17



> Is the Bourne Shell actively developed? Does it have the many new
> interactive features of modern shells like bash or zsh? Does it have
> features for scripting like modern shells (arrays, etc.)?
<snip>
> I'd call a shell without line editing or history mechanism "castrated"
> or "functionality reduced" if you prefer that. Amen.

True, but for scripting purposes it has a few key benefits.  For a start it's
highly standardised and as the lowest-common-denominator you can get an sh
script working pretty much anywhere.  

Additionally the features it lacks makes for a smaller executable meaning it
loads and runs faster than other shells (with the possible exception of rc).
You may not think it would matter that much with modern computers but when
you consider just how much of a Unix system is implemented as shell scripts
I think you would notice the difference.  Admitted Linux tends to come with
bash as sh but you can't easily compare it's performance to a system that
uses a real Bourne shell as sh.

--
Andrew Smallshaw

 
 
 

PS1 value in shells

Post by Sven Maschec » Thu, 09 Jun 2005 04:30:35



> I read it but I didn't understand it

hm, yes,

Quote:> [...] contrary to zsh where "sh" means "emulate sh (Bourne shell).

That's incorrect, too.

zsh-4.2.5/FEATURES: "can emulate ksh or POSIX sh". (These are quite
similar due to their history.) Hence, EMULATE_SH and EMULATE_KSH are
used identically in the zsh source, except for one detail in params.c.

The comment in zsh.h: "#define EMULATE_SH (1<<3) /* Bourne shell */"
in turn is just erroneous.
--
bourne specific: <http://www.in-ulm.de/~mascheck/bourne/common.html>

 
 
 

1. Better Way to Get Value of Value of Variable in Bourne shell?

Hi

I need to create a Bourne shell function that can change/manipulate the values
of the given variable names, e.g.

  $ P1=John
  $ P2=Jane
  $ P3=Paul

  $ echo "1=$P1, 2=$P2, 3=$P3."
  1=John, 2=Jane, 3=Paul.

  $ add_prefix Hi_ P1 P2 P3

  $ echo "1=$P1, 2=$P2, 3=$P3."
  1=Hi_John, 2=Hi_Jane, 3=Hi_Paul.

After several trial-and-error, I finally got the add_prefix() working, but I
think my solution is too complicated and inefficient, specifically the
"eval $var='$prefix`eval echo \\$$var`'" that takes 2 evals and 1 command
substitution, as shown below.

  add_prefix () {
    prefix=$1
    shift
    for var in $*; do
      eval $var='$prefix`eval echo \\$$var`'
    done
  }

Can any Bourne shell programming guru show me a more concise, efficient and
elegant way in writing the add_prefix() function without using any external
command?

Is there any shorter syntax like ${$var} in Bourne shell that can replace
`eval echo \\$$var` ?  Something concise and simpler will be helpful because
the actual function I need to write is much more complicated than add_prefix()
function shown above.

Thanks.  I appreciate your help.

Regards
Hon-Chi

2. aix vs sco

3. How to change the value of PS1 from within a c program

4. Taper & Adaptec 2920-based tape drive question!

5. How to translate Linux's PS1 prompt to Unix's PS1 prompt?

6. XNTPD 3.5.90 and Solaris 2.6

7. PS1='[$PWD]'; how can I reduce the length of PS1 when it is long?

8. Have mail hold awaiting SLIP, how?

9. How to translate Linux's PS1 prompt to Unix's PS1 prompt?

10. shell built ins

11. Shells and built-ins

12. PS1 on bash shell?

13. control PS1 on the bourn shell