Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to source a system file in perl 1

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
Another entry level question:

A simple code named tt.pl:

Code:
my $sysf = '/export/myhome/.cshrc';
my $cmd = "source $sysf";
if(-e $sysf) {
  print "found '$sysf'\n";
  print "\$cmd = $cmd\n";
  system($cmd);
}
print "done\n";

And here is the output:
=======================

Code:
% tt.pl
found '/export/myhome/.cshrc'
$cmd = source /emc/yanc2/.cshrc
[COLOR=red][b]Can't exec "source": No such file or directory at ./source.pl line 12.[/b][/color]
done

The code was run under tcsh on Solaris.

What did I missing here?

Thanks for the help.
 
First of all, I apologize for my typo. Actually in my testing, I named my code as source.pl, not tt.pl. Sorry for the confusion.

Does source.pl exist in the current dir?
So, my answer is: yes, it exists.

If so, does the file or directory named on line 12 exist?

The line 12 is actually 'system($cmd)'. Again, I am so sorry I did not point this out at first place.
 
Try using the full path to source -
my $cmd = "/usr/bin/source $sysf";

(or whatever path you get from "which source")
 
Thanks, chazoid. I tried that before I posted my question here:

Code:
% uname -rsp
SunOS 5.10 sparc
% ps | grep $$
  1278 pts/2       0:00 tcsh
% which source
source: shell built-in command.
 
Thank you again, chazoid.

It is insteresting! I'll look into it over the weekend and will update you later.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top