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 Thu 02 Oct 2014, 09:03
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 Posts_count  
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>
Sub_title: 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

Edited_time_total
Back to top
View user's profile Send_private_message Visit_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: 2252

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: 2507
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
Sub_title: 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_website 
L18L

Joined: 19 Jun 2010
Posts: 2507
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.

Edited_time_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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0594s ][ Queries: 11 (0.0033s) ][ GZIP on ]