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 22 Oct 2014, 10:34
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to read a files content to a variable? <Solved>
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Sun 11 May 2014, 23:23    Post subject:  How to read a files content to a variable? <Solved>
Subject description: read the contents of a one line file and store it in a variable for further use
 

hey!

I'm playing around with "sampling" desktop icons. basically, you choose an icon theme, try it out, if you don't like it, restore your original theme. Much like the icon_switcher but having script remember the original theme.

I thought iI knew how to read the contents of a file Rolling Eyes but apparently i'm not doing something right. So I went back through all the information I could find on it. Now i'm more confused that ever Shocked

I'm certain this is a simple one-line process that i'm just not grasping. I've tried some things such as:
Code:

NewTheme = [cat /etc/desktop_icon_theme]

NewTheme = " ' cat /etc/desktop_icon_theme' "

NewTheme = $('cat /etc/desktop_icon_theme')


and several others. Nothing seems to capture the contents in the variable. Anyone who can, correct my confusion plz Very Happy

Thanks!

E

Last edited by e_mattis on Mon 12 May 2014, 19:36; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
rufwoof

Joined: 24 Feb 2014
Posts: 308

PostPosted: Mon 12 May 2014, 02:16    Post subject:  

Not sure about other keyboards, but for a UK keyboard you use the downward sloping single quote that's just to the left of the 1 key (as in 1 2 3 ..etc)

current_dir=`pwd`

for instance. So for a file

content=`cat somefile`

You can then use that captured data inside the script by prefixing with a $ $current or $content for example
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2258

PostPosted: Mon 12 May 2014, 02:25    Post subject:  

Code:
NewTheme="$(cat /etc/desktop_icon_theme)"

or:
Code:
NewTheme="`cat /etc/desktop_icon_theme`"
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2525
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Mon 12 May 2014, 04:15    Post subject: Re: How to read a files content to a variable
Subject description: read the contents of a one line file and store it in a variable for further use
 

For read use read Very Happy
Code:
read NewTheme < /etc/desktop_icon_theme

which will read one line.
Back to top
View user's profile Send private message 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Mon 12 May 2014, 12:20    Post subject:  

Thanks guys!

I've tried each one of those but get the same results - the icons do not revert back to the original and the test save file (saving as desktop_icon_theme-test) shows nothing in the file - have even had it echo to a window on screen and shows nothing - indicating that the variable does not contain anything.

Is there something i'm missing here?

thanks

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

Joined: 19 Jun 2010
Posts: 2525
Location: Moved from Hosla to www.eussenheim.de

PostPosted: Mon 12 May 2014, 12:56    Post subject:  

If the file is empty then it is OK if the variable is also empty.
What did you expect?
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Mon 12 May 2014, 16:42    Post subject:  

If you are changing the icon theme you'll need to restore this theme - better saying its icons.

Changing a theme overwrites icons in /usr/local/lib/X11/pixmaps with the icons from the theme chosen. These themes are in /usr/local/lib/X11/themes (sub-directory's name is the theme name).

So you would need to call /usr/sbin/icon_switcher or /usr/sbin/icon_switcher_cli and also to submit the original theme.

E.g.
Code:
/usr/sbin/icon_switcher_cli "crystal"

To restore only content of file /etc/desktop_icon_theme just won't work.

_________________
LazY Puppy
RSH's DNA
SARA B.

Last edited by RSH on Mon 12 May 2014, 16:54; edited 1 time in total
Back to top
View user's profile Send private message 
RSH


Joined: 05 Sep 2011
Posts: 2420
Location: Germany

PostPosted: Mon 12 May 2014, 16:54    Post subject:  

This works over here:

Get the original theme and store it:
Code:
read OrigTheme < /etc/desktop_icon_theme
echo $OrigTheme > /tmp/original_icon_theme


Restore to original theme:
Code:
read OrigTheme < /tmp/original_icon_theme
/usr/sbin/icon_switcher_cli "$OrigTheme"

_________________
LazY Puppy
RSH's DNA
SARA B.
Back to top
View user's profile Send private message 
e_mattis


Joined: 20 Dec 2012
Posts: 114
Location: Williamston, SC

PostPosted: Mon 12 May 2014, 18:00    Post subject:  

UPDATE: that seems to have done the trick! Gonna mark it solved and move on. thanks guys! you're awesome!

-----------------------------------------------------------------------------------
thanks guys

@L18L
What I meant was the file I have the program write as a test to see if the variable contained any data was empty, not the file i'm reading from Very Happy

@RSH
Will try that and make sure, but it looks familiar so I think that will work for me. Will let yo know in a little while.

Thanks a lot!

E
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 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.0582s ][ Queries: 11 (0.0029s) ][ GZIP on ]