bash command substitution, functions and quoting : need help
- From: amwyll.codydd@xxxxxxxxx
- Date: Sat, 5 Apr 2008 10:01:47 -0700 (PDT)
Hello everybody.
I've got a question that's been driving me mad for a couple of days
now. It has to do with quoting, command substitution and functions.
I'm trying to generate a format string for PS1 within a function,
return that string from function (via echo) and assign THAT to PS1,
except for some reason the escaping goes all awry in the process.
Please note the prompts (everything below ">") in the below commands
execution sequence with lines numbered on the left (not part of prompt
per se) :
01 prompt> PS1='$( { echo "\[\033[1;34m\]$(date) >\[\033[0m\]
" ; } )'
02 Sat Apr 5 15:01:29 2008 >
03 Sat Apr 5 15:01:30 2008 >
04 Sat Apr 5 15:01:31 2008 > func() { echo "\[\033[1;34m\]$(date) >\
[\033[0m\] " ; } ; PS1='$(func)'
05 \[\033[1;34m\]Sat Apr 5 15:01:37 2008 >\[\033[0m\]
06 \[\033[1;34m\]Sat Apr 5 15:01:39 2008 >\[\033[0m\]
07 \[\033[1;34m\]Sat Apr 5 15:01:40 2008 >\[\033[0m\]
At #01 I assign the output of command substitution directly to PS1,
and as can be observed in #02-#04 it works out perfect (the coloring
worked, date evaluated every time, etc). At #04 I try to assign the
same "echo" output to PS1 but this time "echo" was executed in a
function. As can be observed in #05-#07 the escape sequences were
somehow "garbled" and instead of doing coloring they are reproduced
verbatim. I'm observing this with bash 2.05b and 3.x.
Any ideas as to how I can format the string including bash prompt
color escape sequences inside a function, using bash built-ins only
(e.g. no printf and such), then somehow have the function evaluated
every time and have the output stored into PS1, with all the escape
sequences intact?
Thanks in advance.
.
- Follow-Ups:
- Prev by Date: Please provide me some basic learning material for Shell scripting
- Next by Date: Re: bash command substitution, functions and quoting : need help
- Previous by thread: Please provide me some basic learning material for Shell scripting
- Next by thread: Re: bash command substitution, functions and quoting : need help
- Index(es):
Relevant Pages
|