|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
ksh quote or no quote whitespace madness
The program:
Code:
#!/bin/sh THIS=' aa bb cc dd ee ff' THAT=" zz yy xx ww " echo \"THIS: [\${THIS}]\" echo ------------------- echo "THIS: [${THIS}]" echo echo THIS: [\${THIS}] echo ------------------- echo THIS: [${THIS}] echo echo \"THAT: [\${THAT}]\" echo ------------------- echo "THAT: [${THAT}]" echo echo THAT: [\${THAT}] echo ------------------- echo THAT: [${THAT}] Code:
$ sh this-that "THIS: [${THIS}]" ------------------- THIS: [ aa bb cc dd ee ff] THIS: [${THIS}] ------------------- THIS: [ aa bb cc dd ee ff] "THAT: [${THAT}]" ------------------- THAT: [ zz yy xx ww ] THAT: [${THAT}] ------------------- THAT: [ zz yy xx ww ]
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
What were you expecting? Looks perfectly normal to me J65nko but I'm a bit drowsy....
Code:
Terry@vectra$ echo `cat this-that` #!/bin/sh THIS=' aa bb cc dd ee ff' THAT=" zz yy xx ww " echo \"THIS: [\${THIS}]\" echo ------------------- echo "THIS: [${THIS}]" echo echo THIS: [\${THIS}] echo ------------------- echo THIS: [${THIS}] echo echo \"THAT: [\${THAT}]\" echo ------------------- echo "THAT: [${THAT}]" echo echo THAT: [\${THAT}] echo ------------------- echo THAT: [${THAT}] Quote:
Quote:
echo "$THIS" preserves things just as you would expect, that's the double quotes job. echo $THIS substitutes $THIS with the contents of the THIS variable, which I assume is subject to field splitting. Unless you screw with IFS, echo $THIS should be equivalent to this: Code:
echo aa \ bb \ cc \ dd \ ee \ ff' Maybe I'm just to sleepy or perhaps I missed some trick about the question?
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
|||
I found in this in a on old dump(8) I restored 2 days ago. What else has a man to do on the second day of Christmas?
I cannot recall why I wrote it, probably to show somebody on bsdforums.org who had a problem with this, at least for most beginning sh programmers, whitespace madness. Indeed it has like both of you mentioned something to do with 'IFS' (inter field separator), a shell variable holding the characters, the shell uses to break up a string into words. Code:
$ X='x y z' $ echo "$X" x y z $ echo $X x y z $ IFS_ORIG=$IFS $ IFS='' $ echo $X x y z $ IFS=$IFS_ORIG $ echo $X x y z
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
||||
Quote:
Sorry, couldn't resist
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
Tags |
echo, quotes, sh whitespace |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
interrupt storm and irq madness | siffland | FreeBSD General | 5 | 23rd October 2009 05:16 AM |
escape single quote in sed | gosha | Programming | 5 | 9th March 2009 10:22 AM |