LinuxQuestions.org
Help answer threads with 0 replies.
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-26-2014, 07:07 AM   #1
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Rep: Reputation: 15
Getting the current shell in a perl script


Hi,

I have the following function to get a shell and use the value to execute a
command.
$shell_type = `echo \$SHELL | awk -F/ '{print \$NF}'`;
print "Shell type is $shell_type";
`sudo -E $shell_type -c "/sbin/ifconfig eth0"`;

This prints the shell type as bash, but no output for ifconfig.
When I try to open the file again using vim, I get the following message:
Vim: Warning: Output is not to a terminal

What is wrong in the perl script?

Thanks,
D
 
Old 06-26-2014, 07:55 AM   #2
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Rep: Reputation: Disabled
What do you want to achieve using this?
 
Old 06-27-2014, 01:40 AM   #3
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Original Poster
Rep: Reputation: 15
I am running a perl script as non-root user and want to export some root env variables for non-root.
 
Old 06-27-2014, 02:18 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,678

Rep: Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273Reputation: 7273
you do not need to calculate shell type, you can use it directly sudo -E $SHELL -c .....
But if you want to do that use:
shell_type=${SHELL##*/}
furthermore /sbin/ifconfig eth0 will give you the same result without sudo.

that was for shell, for perl it is similar:
my $shell = $ENV{SHELL};
my $shell_type = ($shell =~ s!.*/!!);

but I still don't know how is it related to your post #3

Last edited by pan64; 06-27-2014 at 02:23 AM.
 
Old 06-29-2014, 12:04 AM   #5
jayadhanesh
Member
 
Registered: Feb 2009
Location: Bangalore
Posts: 61

Original Poster
Rep: Reputation: 15
This is now solved. A chomp on the $shell_type did the trick.
 
  


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
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 09:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 01:03 AM
Shell script, Perl script, command or utility to convert Binary to text Perseus Programming 26 07-12-2012 06:00 AM
how to call a script in a new shell from the current shell Bone11409 Linux - Newbie 2 05-04-2010 04:11 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 09:56 AM

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

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