I'm trying to add a boot script to /etc/profile.local that will export a global environment variable. I need to check the existence of and contents of 2 files. If the first file exists and has an entry, then use that entry plus two characters for the value of the environment variable. If the first file is empty or missing then I need to get the value from the second file and use that plus the two characters if that file exists. If neither file exists or both are empty then a default gets exported.

I can read a file into a variable and export it like this

Code:

#export MY_VARIABLE=$(<$file)-x
#echo $MY_VARIABLE
mydata-x

but what I need to accomplish is beyond my current bash skills.

Help please?

Regards,
Mobeus_________________/root for the home teamLast edited by Mobeus on Wed 20 Mar 2013, 09:41; edited 1 time in total

There are different kinds of global variables :
In the background with no controlling tty like rc.local or rc.services ,
In the console mode after login/autologin (etc/profile)
In X (xwin, /root/.xinitrc)

If the first file exists and has an entry, then use that entry plus two characters for the value of the environment variable. If the first file is empty or missing then I need to get the value from the second file and use that plus the two characters if that file exists. If neither file exists or both are empty then a default gets exported.

Now I know I'm not a complete bash ignoramus I didn't want to post my code until I (hopefully) saw an example. Our code is very similar except I read the data and make sure it's valid. At least that's the idea. Here's what I have that's not working

So, a non breaking space... html. It makes me wonder. I know I've never opened that file in a browser or html editor.

Anyway, did the echo jwm > /etc/widowmanager and that gave a hexdump of '6a 77 6d 0a' so I removed the ending newline and rebooted. Everything still works, and the bash code works as expected now too. And here I was, certain it was something I was doing wrong.

Thanks for taking the time to work through this, SFR. It's been an education

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum