LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 01: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, 07:23 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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 07:25 PM.
 
  


Reply



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 06:34 AM
[SOLVED] sudo in bash script grep environment geep1980 Programming 15 11-28-2011 05:09 AM
How to export environment variable from a bash script dimaash Linux - Newbie 20 08-09-2011 07:12 AM
How to get environment variable from other user in bash script? Moonman Linux - General 5 01-13-2009 11:22 PM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:45 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
Open Source Consulting | Domain Registration