Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Yes, I am a linux newbie, but I'm not stupid. First time using linux and I've managed to find comfort in Gentoo. Alas, I'm stuck on something simple, I just can't find the resource to solve my problem.
I've created a little script to setup my network for my work environment. It's called worknet.sh. I keep it in my home dir, and I run it as root so I can do emerge from work. the contents follow:
(the IPs have been changed.)
My problem is that dhcpcd runs fine, and sets up eth0, but my exports never take cause I end up having to type them in manually after I run the script in order for emerge to find the proxy.
What am I doing wrong?
I don't think that would matter because when I use the export command at the prompt I use all lower case and it works. It's the exact same way in the script.
Well, not wrong, but for Bash global exports are usually done from /etc/profile, /etc/bashrc and the stuff in /etc/profile.d depending on it being a login or non-interactive shell. If you don't want to have it exported globally, then you'd have to remember those exports will only live as long as you run that script. here's an outline of how things get sourced by default:
If "emerge" doesn't require arguments, just tack it onto the script at the end, if "emerge" does, then you can supply them on the commandline:
#!/bin/sh
# Check if the interface is up already
/sbin/ifconfig eth0 2>/dev/null|tr -s " "|grep -qe "^ UP";
case "$?" in 0) ;; *) dhcpcd eth0;; esac
# Minimal check if exported values are available
case "${#http_proxy}" in
0) export http_proxy="hteeteep://ipaddress.that.it.won't.let.me.postort";; esac
case "${#ftp_proxy}" in
0) export ftp_proxy="fteep://ipaddress:21";; esac
case "$@" in
0) echo "Running emerge with no options"; emerge;;
*) case "$1" in
h|-h|--help) echo "$(basename $0) <emerge options>"; exit 1;;
*) echo "Running emerge with options \"$@\""; emerge "$@";;
esac;;
esac
Basically, exports are only inherited by child processes, and cannot be "pushed back up the process tree".
Your shell script sets some variables, they are available in that script only. You export them, and they are available in processes initiated by that script. But regardless of what you do, once that script exits the variables go away.
When you type them in, you're setting them in the current environment space, rather than in a script's private space.
This is a fundamental design feature of *nix. It's called "inheritance" because it only goes one way...
Maybe what you want to do is call dhcpcd at boot time, then set your variables at login time. Or do both at login time from .profile or .bashrc .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.