Jump to content

help translating perl to bash


Guest wassup
 Share

Recommended Posts

Hi everyone, i need to translate this perl script to bash, if someone could help me i would really appreciate it!

#!/usr/bin/perl

use strict;


my @data = `echo /home \`pwd\``;

my %data;
foreach my $line (@data){
chomp($line);
next if !$line;
$line =~ s/(\/cd.*?)$//;
$data{$line}++;
}
open(WRT," >> /home/user/log.txt");
foreach my $data (keys %data){
print WRT "$data\n";
}
close(WRT);

thanks in advance!

Link to comment
Share on other sites

Sorry, I don't quite get what this script is supposed to do. Do you know?

 

It looks like the first line builds a string like "/home /home/user/current/working directory"

But then when you loop through this, there's only one entry, which is the string itself, so there's no looping going on.

Then you do some replacing, deleting stuff which starts with /cd, and then you append that modified string to the log flie.

 

I don't get the point! :unsure: are you trying to list files here?

Link to comment
Share on other sites

When you run that perl script on your machine, does it do what you want it to do? Because like I said, it doesn't appear to do what you want.

 

Have you tried something like

find /home/user/some/path -type d -mtime -2

to give a list of recently modified (not created) directories under the given path?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...