Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 12 Dec 2018, 21:15
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
trailing whitespace (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
don570


Joined: 10 Mar 2010
Posts: 5209
Location: Ontario

PostPosted: 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
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1711
Location: Japan

PostPosted: 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
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 5209
Location: Ontario

PostPosted: 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. Embarassed
Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 5209
Location: Ontario

PostPosted: 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
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 5209
Location: Ontario

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

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.0498s ][ Queries: 12 (0.0045s) ][ GZIP on ]