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 Sun 09 Dec 2018, 16:30
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog - tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 97 of 97 [1448 Posts]   Goto page: Previous 1, 2, 3, ..., 95, 96, 97
Author Message
don570


Joined: 10 Mar 2010
Posts: 5195
Location: Ontario

PostPosted: Sun 18 Nov 2018, 15:00    Post subject:  

echo command can have options . I would try echo -n

or maybe echo -e and then use \n for a new line.

http://linuxcommand.org/lc3_man_pages/echoh.html
_____________________________________________
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3480
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sun 18 Nov 2018, 17:43    Post subject:  

Thanks.
In the script above, the temporary text file is built at startup using the echo command only as example, but in reality, this text file is a list of files (built with the find command) which can have spaces in their path and in their name (example: /root/.moonchild productions/pale moon/xxx). It is these files that are problematic and are processed in segments instead of in one piece.
What could be done to avoid this?

_________________

Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1683

PostPosted: Sun 18 Nov 2018, 18:01    Post subject:  

Argolance wrote:
What could be done to avoid this?

This, for example:
Code:
while read -r LINE; do
LIST="${LIST}
   <checkbox>
      <variable>$LINE</variable>
      <default>true</default>
      <label>$LINE</label>
      <action>if false disable:$LINE</action>
      <action>sed -i 's/$LINE//' /tmp/checkbox_test</action>
      <action>refresh:TEXT</action>
   </checkbox>
"
done < /tmp/checkbox_test

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3480
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Sun 18 Nov 2018, 18:04    Post subject:  

Oh yes, thank you SFR! Very Happy
_________________

Back to top
View user's profile Send private message Visit poster's website 
some1

Joined: 17 Jan 2013
Posts: 89

PostPosted: Sun 18 Nov 2018, 20:23    Post subject:  

Argolance,SFR:Nice Smile
----
Argolance:
Quote:

this text file is a list of files (built with the find command) which can have spaces in their path and in their name (example: /root/.moonchild productions/pale moon/xxx).

With your demo - try som slashes in the DATA:
Code:

echo "My_tailor_is_rich
My/tailor/is/NOT/rich" > /tmp/checkbox_test
 


and consider this:
Code:

 <action>sed -i 's/$LINE//' /tmp/checkbox_test</action>


In the sed command -you can use | or some other char - instead of the default- /-s -but...?

The i-switch in sed may be convenient - but sed is in reality rewriting the whole file using a tempfile - which is moved to be the updated input-file.
Alternatively-we can emulate that -using awk,grep -v or a read-loop to update the input-file via a tempfile every time we choose a $LINE to be excluded.


----
Anyway -Nice demo.
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3480
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Mon 19 Nov 2018, 05:46    Post subject:  

Bonjour,
some1 wrote:
In the sed command -you can use | or some other char - instead of the default- /-s -but...?

Yes indeed: my "real" script (allowing user to set the font of the UI of browsers like Seamonkey, Firefox, Pale Moon and some others, according to the current GTK theme or any else) uses %, because of the / that are in the found files paths (profiles.ini)...
Code:
CSS_FILE="$(cat /tmp/PROF_PATHS)"

while read -r LINE; do
PROFILES_LIST="${PROFILES_LIST}
   <checkbox tooltip-text=\" $(gettext "If unchecked, the 'userChrome.css' configuration file of this profile will not be modified") \">
      <variable>$LINE</variable>
      <default>true</default>
      <label>$LINE</label>
      <action>if false disable:$LINE</action>
      <action>sed -i 's%${LINE}%%' /tmp/PROF_PATHS</action>
   </checkbox>
"
done < /tmp/PROF_PATHS


Cordialement.

_________________

Back to top
View user's profile Send private message Visit poster's website 
don570


Joined: 10 Mar 2010
Posts: 5195
Location: Ontario

PostPosted: Mon 19 Nov 2018, 14:11    Post subject:  

There is no need to use the read command. Your original script will work with a small change....

Last nite I read Advanced Bash manual
and the answer is to change the IFS

Here's an example with filenames rather than data in a file....

Quote:


Filenames with embedded whitespace can cause globbing to choke. David Wheeler shows how to avoid many such pitfalls.

1 IFS="$(printf '\n\t')" # Remove space.
2
3 # Correct glob use:
4 # Always use for-loop, prefix glob, check if exists file.
5 for file in ./* ; do # Use ./* ... NEVER bare *
6 if [ -e "$file" ] ; then # Check whether file exists.
7 COMMAND ... "$file" ...
8 fi
9 done
10
11 # This example taken from David Wheeler's site, with permission.


Here's script with two extra lines...
Code:
#!/bin/sh

echo  -n "My_tailor_is_rich
My tailor is NOT rich" > /tmp/checkbox_test

FILE="`cat /tmp/checkbox_test`"
I=$IFS; IFS="$(printf '\n\t')"

for LINE in $FILE; do
LIST="${LIST}
   <checkbox>
      <variable>$LINE</variable>
      <default>true</default>
      <label>$LINE</label>
      <action>if false disable:$LINE</action>
      <action>sed -i 's/$LINE//' /tmp/checkbox_test</action>
      <action>refresh:TEXT</action>
   </checkbox>
"
done
IFS=$I
export MAIN="
<window window_position=\"1\">
   <vbox>
      <hbox border-width=\"5\">
         <frame Text (/tmp/checkbox_test)>
            <edit>
            <input file>/tmp/checkbox_test</input>
            <variable>TEXT</variable>
            </edit>
         </frame>
         <frame Checkboxes>
            ${LIST}
         </frame>
      </hbox>
      <hbox>
      <button><input file stock=\"gtk-undo\"></input>
         <label>$(gettext 'Reset')</label>
         <action>EXIT:restart</action>
      </button>     
         <button cancel></button>
      </hbox>
   </vbox>
</window>
"
I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog --program=MAIN); do
   eval $STATEMENTS
done
IFS=$I

[ "$EXIT" = "restart" ] && $0
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 3480
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Mon 19 Nov 2018, 20:45    Post subject:  

Hello,
Great! Smile
These "tips" are both welcome and work perfectly! I think we're never done learning...
Thank you a lot.

Cordialement.

_________________

Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 97 of 97 [1448 Posts]   Goto page: Previous 1, 2, 3, ..., 95, 96, 97
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.1466s ][ Queries: 13 (0.0802s) ][ GZIP on ]