The Hindmost has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm currently modifying the Linux connection shell script for my University's network (to improve efficiency and connection success) and have found an interesting conundrum: bash works fine as a shell, sh doesn't (no known data for other shells yet).
So I've written a small perl program to pull the current shell out of env's output and warn the user if they're not running bash (code below):
#!/usr/bin/perl -w # shellGet.pl # A program to return the current shell of the user # # Christopher Dykes (2008-09-30) #Use the following modules: use strict; #Use strict syntax use warnings; #Enable warnings #Get the environment data write it externally and open it for use: system("env > .env.txt"); open(ENV, ".env.txt") || die("Couldn't open environment data file: $!" +); while(my $fileLine = <ENV>) #Read in our environment fi +le { if($fileLine =~ /SHELL=/) #Search for the shell line { my @shellLine = split(/=/, $fileLine); #Extract the relevan +t portion print "$shellLine[1]"; #Display our shell #All done: close ENV; #Close the environment file system("rm .env.txt > /dev/null"); #Clean up the environmen +t file exit; #And Quit } } #We shouldn't get here unless there's been an error: die("\aError: Couldn't find SHELL\texiting\n");
This works, but it's more a question of efficiency is this the fastest way to do this (unlikely) and if there is a faster way can you give me any hints.
Thanks in advance Chris
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Environment discovery under Linux
by plobsing (Friar) on Sep 30, 2008 at 07:57 UTC | |
by moritz (Cardinal) on Sep 30, 2008 at 08:06 UTC | |
by FunkyMonk (Chancellor) on Sep 30, 2008 at 21:41 UTC | |
by The Hindmost (Scribe) on Sep 30, 2008 at 08:04 UTC | |
Re: Environment discovery under Linux
by rovf (Priest) on Sep 30, 2008 at 08:06 UTC | |
by The Hindmost (Scribe) on Sep 30, 2008 at 08:30 UTC | |
Re: Environment discovery under Linux
by Corion (Patriarch) on Sep 30, 2008 at 08:03 UTC | |
Re: Environment discovery under Linux
by lamp (Chaplain) on Sep 30, 2008 at 08:08 UTC | |
Re: Environment discovery under Linux
by JavaFan (Canon) on Sep 30, 2008 at 09:41 UTC | |
Re: Environment discovery under Linux
by toolic (Bishop) on Sep 30, 2008 at 13:17 UTC | |
Re: Environment discovery under Linux
by Wiggins (Hermit) on Sep 30, 2008 at 13:46 UTC | |
Re: Environment discovery under Linux
by gloryhack (Deacon) on Sep 30, 2008 at 17:05 UTC | |
Re: Environment discovery under Linux
by graff (Chancellor) on Oct 01, 2008 at 04:46 UTC |
Back to
Seekers of Perl Wisdom