The time now is Wed 20 Jan 2021, 22:54
All times are UTC - 4 |
Author |
Message |
don570

Joined: 10 Mar 2010 Posts: 5524 Location: Ontario
|
Posted: Wed 27 Dec 2017, 18:19 Post subject:
trailing whitespace (Solved) |
|
There is a strange behaviour I noticed with trailing whitespace.
The following isn't successful...
Code: | # A="Note: ";[ $A = "Note: " ] && echo successful |
If I assume that there is no trailing whitespace....
Code: |
# A="Note: ";[ $A = "Note:" ] && echo successful
successful
|
An extra layer of brackets also solves the problem....
Code: |
# A="Note: ";[[ $A = "Note: " ]] && echo successful
successful
|
______________________________________________________
I checked with a gtkdialog script and there doesn't appear to be any
problem with trailing whitespace.
Code: |
#!/bin/bash
# whitespace experiment
export DIALOG='<window>
<vbox>
<frame>
<hbox>
<entry>
<default>"Note: "</default>
<variable>MESSAGE</variable>
</entry>
</hbox>
</frame>
<button ok>
</button>
</vbox>
</window>
'
I=$IFS; IFS=""
for STATEMENTS in $(gtkdialog --geometry=+200+100 --program DIALOG); do
eval $STATEMENTS
done
# check for trailing whitespace
A="$MESSAGE";[ $A = "Note: " ] && xmessage success
|
____________________________________
|
Back to top
|
|
 |
MochiMoppel

Joined: 26 Jan 2011 Posts: 2084 Location: Japan
|
Posted: Wed 27 Dec 2017, 22:10 Post subject:
Re: trailing whitespace |
|
don570 wrote: | The following isn't successful...
Code: | # A="Note: ";[ $A = "Note: " ] && echo successful
|
|
A="Note: ";[ "$A" = "Note: " ] && echo successful
Quote: | I checked with a gtkdialog script and there doesn't appear to be any problem with trailing whitespace. | ...because you didn't change $IFS back to its default value.
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 5524 Location: Ontario
|
Posted: Fri 29 Dec 2017, 16:18 Post subject:
|
|
Quote: | you didn't change $IFS back to its default value |
I hadn't thought about IFS.
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 5524 Location: Ontario
|
Posted: Tue 02 Jan 2018, 13:42 Post subject:
|
|
I need to read more about IFS. It's mentioned in.
Advanced Bash Manual
_____________________________________________________
________________________________________________________
Code: | $IFS defaults to whitespace (space, tab, and newline), but may be changed, for example, to parse a comma-separated data file. Note that $* uses the first character held in $IFS. See Example 5-1.
bash$ echo "$IFS"
(With $IFS set to default, a blank line displays.)
bash$ echo "$IFS" | cat -vte
^I$
$
(Show whitespace: here a single space, ^I [horizontal tab],
and newline, and display "$" at end-of-line.)
bash$ bash -c 'set w x y z; IFS=":-;"; echo "$*"'
w:x:y:z
(Read commands from string and assign any arguments to pos params.)
Set $IFS to eliminate whitespace in pathnames.
IFS="$(printf '\n\t')" # Per David Wheeler. |
|
Back to top
|
|
 |
don570

Joined: 10 Mar 2010 Posts: 5524 Location: Ontario
|
Posted: Tue 02 Jan 2018, 13:44 Post subject:
|
|
I noticed that someone has put up a good page with examples to
explain gtkdialog
http://xpt.sourceforge.net/techdocs/language/gtkdialog/gtkde02-GtkdialogExamples/
____________________________________________
|
Back to top
|
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
[ Time: 0.0808s ][ Queries: 11 (0.0156s) ][ GZIP on ] |