Learning Bash: Quoting spaces

From: Sak (sak_at_invalid.address)
Date: 09/30/03


Date: Mon, 29 Sep 2003 23:20:40 -0700

Everyone,

I'm working through O'Reilly's 'Learning the bash shell' and have run into
some questions. Here's the first one:

The following function is offered in Chapter 4

pushd ()
{
     dirname=$1
     DIR_STACK="$dirname ${DIR_STACK:-$PWD' '}"
     cd ${dirname:?"missing directory name."}
     echo "$DIR_STACK"
}

When I run this, the first directory that gets pushed onto the stack gets a
literal ' ' at the end of it, while the subsequent directories pushed onto
the stack do not. Like this...

/home/sak/wip/composition/ /home/sak/wip/lup/ /home/sak' '

I've managed to figure out that if I remove the strong quotes from around
the space, like this...

DIR_STACK="$dirname ${DIR_STACK:-$PWD }

...I get the desired result. I was just wondering why? In the previous
case, why did the literal quotes only end with the first item pushed onto
the stack, and not the rest?

-- 
Thanks,
Sak.


Relevant Pages

  • Re: frustration with starting forth
    ... stack until I finally get it.....but a week later I've no clue how i ... Learning Forth is a different process from learning most ... As others in this thread have said, the two keys are: ... definition as equivalent to a subroutine in some other language ...
    (comp.lang.forth)
  • Re: frustration with starting forth
    ... Learning Forth is a different process from learning most programming languages, because of the stack, and the enormous command set. ... In some respects it's like learning a new human language: you have to develop a lot of vocabulary before you can express yourself effectively. ... the practice of putting one short phrase per line and then a comment showing what's on the stack at the end of that phrase is very helpful. ...
    (comp.lang.forth)
  • Re: [OT] PostLisp, a language experiment
    ... >> Why are we still talking about runtime efficiency? ... > it's quite easy to model the stack behavior and avoid mismatches. ... > Learning to manage the stack in Forth is a lot like learning to ride a ... >> apparently no runtime checks for stack mismatches, ...
    (comp.lang.lisp)
  • Re: [OT] PostLisp, a language experiment
    ... Counting characters in the name is utterly unrelated to runtime ... to model the stack behavior and avoid mismatches. ... Learning to manage the stack in Forth is a lot like learning to ride a ...
    (comp.lang.lisp)
  • Re: OT - Buffer Overflows, was Re: simple c-code
    ... > I'd like to clarify that this is OT for the thread but not for the ... > newsgroup. ... I think learning about the stack and how to write secure C code ...
    (comp.lang.c)