Guys I love the parser! It is not 100% clear to me how it handles multiple spaces in a row. As far as multiple carraige returns, the behavior of read is to include blank lines as output and the behavior or for with /n as the delimiter is to skip them. Both however, treat multiple unquoted spaces or tabs as if the were one.
I assume we can add another inString variable for single quotes (') and add $'\t' (tab) to the second case condition in Chubler_XL's version.
Hmm . . . I had kind of assumed that ' was "superior" to ". Actually whichever one comes first is "superior"
So inStringSingle if active would have not not count " and inStringDouble if active would not count '.
Meanwhile, I have the mailer to the point that I can use it for the purpose I wrote it. I will return to it in the future to make it much nicer. I've decided that my \n workaround when I loop through the command list is actually a feature since so many e-mail strings and other things SMTP have spaces and will pass them one per line with spaces on STDIN. When I add options and $@, I will just add /n characters to the command string between $1, $2, etc. as BASH already parses quotes in arguments neatly.
Anyway, here is the script in working (but not complete form).
Last edited by Michael Stora; 07-24-2014 at 02:12 PM..
Guys I love the parser! It is not 100% clear to me how it handles multiple spaces in a row. As far as multiple carraige returns, the behavior of read is to include blank lines as output and the behavior or for with /n as the delimiter is to skip them. Both however, treat multiple unquoted spaces or tabs as if the were one.
I assume we can add another inString variable for single quotes (') and add $'\t' (tab) to the second case condition in Chubler_XL's version.
Yes I did consider single quotes but thought the implementation added nothing interesting and detracted from the elegance of the example so consider that an "exercise for the reader". Backslash support is quite interesting, and as read only consumes single characters, it can be achieved with a single line case clause.
I didn't consider multiple white space, and this requires another state variable:
In relation to random string generation: if you have openssl you could also use:
Last edited by Chubler_XL; 07-25-2014 at 02:18 AM..
Reason: Tweaking to match functionality with read built-in
Guys I love the parser! It is not 100% clear to me how it handles multiple spaces in a row.
The way i wrote it the (unquoted) blank is a "terminal" (an expression ending the current parsing entity) - several consecutive terminals produce empty parsing entities, unless explicitly suppressed. You can do that in the " " part of the case-construct by inserting something like:
As for a little theory behind all that: i suggest the "Dragon Book": "Principles of Compiler Design"; Sethi, Aho, Ullmann. IMHO a must for the library of any programmer. It should be the third book apprentices buy, after the TAOCP by Knuth and "The C Programming Language" by Kernighan/Ritchie.
Quote:
Originally Posted by sreyan32
I assume we can add another inString variable for single quotes (') and add $'\t' (tab) to the second case condition in Chubler_XL's version.
Hmm . . . I had kind of assumed that ' was "superior" to ". Actually whichever one comes first is "superior"
It is a - rather common - misconception that quoting can in any way be nested. I can not! In fact the shell works the same way as my parser: it maintains a flag "inside/outside quoted string" which is switched upon every occurrence of a quote (bar escaping, etc.). So "...."...."....." is read: inside quotes after first, outside after second, inside after third and outside again after fourth quote char.
A single quote inside a double-quoted string (and vice versa) is treated as a normal character without any special meaning.
Hi got this issue and was wondering if someone could please help out ?
var='." "'
echo $var
." "
I 'll get ." " and not ." with 10 spaces in between "
Thanks (3 Replies)
I am unable to expand the value of entry variable inside the nawk command.
I tried three different nawk command as below but none of them substitute the value of entry variable.
ls *.txt | while IFS='' read -r entry; do
#nawk '/<name>/{A=1;++i} A{print >> ("cmd"i"_"$entry)}... (9 Replies)
Hi All,
OS - Suse 10
ksh --version
version sh (AT&T Research) 93s+ 2008-01-31
I am passing two words within double quotes ("Application Developer") to script as variable, but script is adding two single quotes between two words like ("Application' 'Developer").
below is simple test... (4 Replies)
As the title says I'm running a korn script in attempts to find an exact match in named.conf
finddomain.ksh
#!/bin/ksh
#
echo "********** named.conf ************"
file=/var/named/named.conf
for domain in `cat $1`
do
grep -n '"\$domain "' $file
done
echo "********** thezah.inc... (1 Reply)
I need to interpolate a shell variable in a code, i cannot share the exact code so this is an example i made up to describe the situation
What I am trying to do here is try to wrap up the value of a variable in single quotes. This value needs to be passed to another program which would only... (4 Replies)
Hi i have to insert the below line into a specific line number of another file
export MBR_CNT_PRCP_TYPE_CODES_DEL="'01','02','04','05','49','55','UNK'"
I have passed the above line to a variable say ins_line. I have used below command to perform the insert
awk 'NR==3{print "'"${ins_line}"'"}1'... (1 Reply)
Hi,
I am generating html code using cshell, but i am having one problem while printing double quotes,
I need to write following code in file. where $var contains list of web address
<a href="$var">$var</a>
So i am using
echo "<a href="$var">$var</a>" > file.html
But with this " in... (4 Replies)
This is a totally dumb newbie question, but I have not been able to find t he answer in the BASH book or online.
I am trying pass a double quoted variable to the command line.
variable = "-b \"dc=example,dc=com\""
When I run sh -x the variable comes out as '-b "dc=example,dc=com"' is... (4 Replies)