You are not logged in.

#1 2012-10-31 00:01:52

oldtimeyjunk
Member
From: /world/europe/uk/england
Registered: 2011-04-30
Posts: 202
Website

[SOLVED] Change environment variables with Shell scripts

How can I change the "BROWSER" environment variable with a shell script; so I can change it on the fly?

Last edited by oldtimeyjunk (2012-10-31 12:57:42)


"... being a Linux user is sort of like living in a house inhabited by a large family of carpenters and architects. Every morning when you wake up, the house is a little different. Maybe there is a new turret, or some walls have moved. Or perhaps someone has temporarily removed the floor under your bed." - Unix for Dummies, 2nd Edition

Offline

#2 2012-10-31 01:44:36

rk700
Member
Registered: 2011-08-21
Posts: 9
Website

Re: [SOLVED] Change environment variables with Shell scripts

export BROWSER=your_browser

Offline

#3 2012-10-31 02:14:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: [SOLVED] Change environment variables with Shell scripts

rk700, that will not work as it will only "export" the variable into the shell that is running the script.  When the script ends, so to does the lifetime of that variable setting.

I have wondered a bit about this myself, unfortunately I haven't had any luck yet.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2012-10-31 02:18:26

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: [SOLVED] Change environment variables with Shell scripts

If you just want to do it for BROWSER so that you can change your default web browser on the fly, you could set BROWSER to e.g. ~/bin/mybrowser and create a symlink to the browser you want at ~/bin/mybrowser. Then you could change the symlink at will.

EDIT: man xdg-settings

Last edited by cfr (2012-10-31 02:20:16)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#5 2012-10-31 02:20:19

rk700
Member
Registered: 2011-08-21
Posts: 9
Website

Re: [SOLVED] Change environment variables with Shell scripts

hmm, how about xdg-settings

Offline

#6 2012-10-31 12:56:19

oldtimeyjunk
Member
From: /world/europe/uk/england
Registered: 2011-04-30
Posts: 202
Website

Re: [SOLVED] Change environment variables with Shell scripts

rk700 wrote:

export BROWSER=your_browser

I have tried that, but as Trilby said, it doesn't work as it should.

The idea suggested by cfr could do the trick. I will also look at XDG Settings.

Thanks!


"... being a Linux user is sort of like living in a house inhabited by a large family of carpenters and architects. Every morning when you wake up, the house is a little different. Maybe there is a new turret, or some walls have moved. Or perhaps someone has temporarily removed the floor under your bed." - Unix for Dummies, 2nd Edition

Offline

#7 2012-10-31 23:38:17

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,362

Re: [SOLVED] Change environment variables with Shell scripts

I do this for setting http_proxy etc, basically I set the values in a file and then have that file sourced in my .zshrc.local

Its kind of a hack though as currently running terminals/apps don't get the changed values.


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

Board footer

Powered by FluxBB