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.

#!/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";
                }
        }
}
commented: great ! This post has given me a valuable piece of information that I've been trying to get ...Thanks a lot +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.