LinuxQuestions.org
Visit Jeremy's Blog.
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 03-17-2015, 05:17 AM   #1
mick66
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Rep: Reputation: Disabled
bash script non-interactive login shell


Hi

I'm focusing on getting my head around interactive v non-interactive shells, both non-login and login. Basically what scripts are run and how local and global variables behave.

I'm pretty much there except for 'non-interactive login shells'. I understand that 'non-interactive' shells are started when a script is run. However, if I start my script with #!/bin/bash --login, then a 'non-interactive login' shell will be started.

In my mind I would have expected this to be the same as logging in from scratch, albeit without a user\password prompt. In this case I would have thought that any exported variables from the parent shell would be blown away. This doesn't appear to be the case. The 'non-interactive login' shell appears to inherit the environment of its parent 'interactive' shell.

Can anyone explain the purpose of a 'non-interactive login' shell and how they behave in this regard.

Hope this makes sense.

Cheers

Mike

Last edited by mick66; 03-17-2015 at 05:18 AM.
 
Old 03-17-2015, 06:23 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
see man bash and look for the related files, initialization. Environment is always inherited, but every process can modify it ....
 
Old 03-17-2015, 06:41 AM   #3
mick66
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi

thanks for the reply but are you sure that's right ... environment is always inherited.

If I export a bunch of variables and start an interactive shell as in [mick@box1]> bash
then yes the variables are inherited.

If I do [mick@box1] > su tom then I've started an interactive shell under 'toms' login ... but not a login shell so 'micks' environmental variables are inherited.

If I do [mick@box1] > su - tom then I've started an interactive login shell and 'micks' environment isn't inherited.

So I guess environmental variables aren't always inherited.

My question was ... how do non-interactive login shells behave and why would you use one? As in bash scripts starting #!/bin/bash --login

Cheers

Mike
 
Old 03-17-2015, 06:44 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
yes, please read the man page first. First the environment was inherited, next some parts were updated, overwritten or just dropped. Regarding env vars you can specify if you want to inherit that given var (those are the exported variables) or not at all.
 
Old 03-17-2015, 07:06 AM   #5
mick66
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hi

to be honest ... I've read the man pages ... and I don't understand them fully. That's why I'm on a 'newbie forum'.

Cheers

Mick
 
Old 03-17-2015, 09:20 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
so please post your questions, what is your problem exactly? first a shell started (inheriting the environment of its parent), next depending on its state (login and/or interactive) some initialization will occur.
 
  


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
Replace login prompt with interactive bash script on serial port neo3matrix Linux - General 1 01-21-2015 12:07 PM
BASH Shell Differences: Login or Interactive theKbStockpiler Programming 10 02-21-2011 01:00 AM
Bash script not running on shell login. uncle-c Linux - Newbie 8 02-21-2009 09:41 AM
setting a timeout in an interactive bash shell script steven.c.banks Linux - General 2 01-23-2009 04:07 PM
BASH - How to open an interactive script from a non interactive script..... OldGaf Programming 4 06-29-2008 04:34 PM

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

All times are GMT -5. The time now is 05:09 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