LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-16-2012, 02:25 AM   #1
jfjh201
LQ Newbie
 
Registered: Jun 2012
Posts: 2

Rep: Reputation: Disabled
bash - script not see environment variable running under sudo


step1.sh
Quote:
#!/bin/bash


echo ${myvar}
Quote:
jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$ export myvar=100
jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$ ./step1.sh
100
jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$ sudo ./step1.sh

jfjh@jfjh-pc:/mnt/gentoo/home/jfjh/lfs-scripts$
os is ubuntu 12.04
 
Old 06-16-2012, 08:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

sudo, by default, doesn't preserve the environment.

Try running w/ sudo -E


For details:
Code:
man 5 sudoers
/env_reset
Cheers,
Tink

Last edited by Tinkster; 06-16-2012 at 08:25 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash - script not see environment variable running under sudo jfjh201 Linux - Software 1 06-16-2012 07:34 AM
[SOLVED] sudo in bash script grep environment geep1980 Programming 15 11-28-2011 06:09 AM
How to export environment variable from a bash script dimaash Linux - Newbie 20 08-09-2011 08:12 AM
How to get environment variable from other user in bash script? Moonman Linux - General 5 01-14-2009 12:22 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 02:45 AM


All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration