| | |
Execute Unix commands from Perl script
![]() |
•
•
Join Date: Mar 2005
Posts: 30
Reputation:
Solved Threads: 0
Hi everyone,
Ps I'm new to Perl (but have been working on Unix for a while) and I'm trying to develop my skills by taking on a project . I am trying to create a perl script that when executed behaves like a Unix Shell, but I need help on how to capture user inputs and then run them as commands at the prompt.
For example , when the perl script is run and the user types ls ., I want to capture the ls, store it in a variable...say $input , and then run the ls command so that all files listed in the current working directory are listed.
Kindly explain how to go about this to me as this is the foundation of the larger picture that I have in mind.
Thanks in advance.
NB. If you know any online resource that will help in this work, kindly let me know.
Ps I'm new to Perl (but have been working on Unix for a while) and I'm trying to develop my skills by taking on a project . I am trying to create a perl script that when executed behaves like a Unix Shell, but I need help on how to capture user inputs and then run them as commands at the prompt.
For example , when the perl script is run and the user types ls ., I want to capture the ls, store it in a variable...say $input , and then run the ls command so that all files listed in the current working directory are listed.
Kindly explain how to go about this to me as this is the foundation of the larger picture that I have in mind.
Thanks in advance.
NB. If you know any online resource that will help in this work, kindly let me know.
Perl Syntax (Toggle Plain Text)
#!/usr/bin/perl while ($uinput ne "quit") { print "# "; $uinput = <>; chomp($uinput); if ($uinput eq "ls") { open(LS, "ls -AF1 |"); while (<LS>) { chomp; push @flist, $_; } close(LS); foreach $file (@flist) { print "$file\n"; } } }
![]() |
Similar Threads
- how to read unix profile variable into Perl (Perl)
- problem in running perl script (Perl)
- Perl, Expect, Cygwin, SSH, and ID Creation / Password Maintenance (Perl)
- Unix shell access from Perl script (Perl)
- How to modify this perl script and make it running in Linux , solaris and windowXP? (Perl)
- A simple perl script (Perl)
- perl script help re: scope/structure for noob (Perl)
- How to execute .exe file from the perl script (Perl)
Other Threads in the Perl Forum
- Previous Thread: problems writing multiple files
- Next Thread: How do you do efficient array (de)referencing?
| Thread Tools | Search this Thread |






