LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-26-2003, 05:52 PM   #1
BertsBackyard
LQ Newbie
 
Registered: Jan 2003
Posts: 4

Rep: Reputation: 0
More perl scripting fun


Im also trying to write a perl script, I want to write a command that renames files, ie mvname [from] [to]. I want to use mv to rename one at a time. Any ideas?
 
Old 01-27-2003, 09:00 AM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
I'm not sure I see the point in this - there's already a perfectly good mv command, so there's no practical reason to write this. And if it's an exercise, you should be working it out for yourself, surely?

Alex
 
Old 01-27-2003, 11:56 AM   #3
lackluster
Member
 
Registered: Apr 2002
Location: D.C - USA
Distribution: slackware-current
Posts: 488

Rep: Reputation: 30
`mv $ARGV[0] $ARGV[1]`;
 
Old 01-27-2003, 05:14 PM   #4
BertsBackyard
LQ Newbie
 
Registered: Jan 2003
Posts: 4

Original Poster
Rep: Reputation: 0
Im trying to do this without mv, if it isnt possible thats ok..I just wanted to write a script that changed a series of program names and not the extensions to something else, ie mvname files backup should change all programs files.* to backup.*.

Bert
 
Old 01-27-2003, 09:37 PM   #5
Darin
Senior Member
 
Registered: Jan 2003
Location: Portland, OR USA
Distribution: Slackware, SLAX, Gentoo, RH/Fedora
Posts: 1,024

Rep: Reputation: 45
Quote:
Originally posted by BertsBackyard
Hit your 1000th post huh

If it is all open source, could you just find the code that the mv command uses? That's probably not in pearl tho, nevermind I'll just crawl back into my non programmer's club hole now.
 
Old 01-27-2003, 10:45 PM   #6
BertsBackyard
LQ Newbie
 
Registered: Jan 2003
Posts: 4

Original Poster
Rep: Reputation: 0
So where would I find the source code for such linux commands?
 
Old 01-29-2003, 05:07 PM   #7
BertsBackyard
LQ Newbie
 
Registered: Jan 2003
Posts: 4

Original Poster
Rep: Reputation: 0
the script with errors

Here is my perl script so far:
____________________________________________________
#!/usr/bin/perl -w
if (! @ARGV) {
$0 =~ s/.*\///;
print "usage: $0 [from] [to]\n";
exit;
}
$from = $ARGV[1];
$to = $ARGV[2];
while (-e '$from.*'){
system "mv $from.* $to.*";
}
____________________________________________________
Any suggestions will be greatly appreciated.

Peace
Bert
 
Old 01-29-2003, 05:11 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
you want THE suggestion.... use strict;
 
Old 01-30-2003, 05:02 AM   #9
xiaoxizhen
LQ Newbie
 
Registered: Jan 2003
Posts: 3

Rep: Reputation: 0
The RPM fileutils contains ls ,mv,cp,rm,mkdir,etc
To get source Please install fileutils-src
 
Old 01-30-2003, 08:00 AM   #10
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
If you want to see what mv does, try:

strace mv file1 file2
 
Old 01-30-2003, 08:11 AM   #11
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally posted by xiaoxizhen
The RPM fileutils contains ls ,mv,cp,rm,mkdir,etc
To get source Please install fileutils-src
heh i'm sure bert is quite aware of mv, he's just trying to learn perl...
 
Old 01-30-2003, 08:33 AM   #12
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
A shell command is quite low level, and it probably uses a system call. Exactly what the system call function name is, I have no idea. I think though that if you wanted to build your own shell, than you would have to be familiar with the system calls of kernel mode functions.
 
Old 01-30-2003, 08:54 AM   #13
xiaoxizhen
LQ Newbie
 
Registered: Jan 2003
Posts: 3

Rep: Reputation: 0
This link to kernel 2.2 system calls,
http://world.std.com/~slanning/asm/syscall_list.html
I hope it will help you.
 
  


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
Perl guys! Time delay 4 Eliza bot Gaim response - want to have fun :) lrt2003 Programming 1 10-03-2004 12:04 PM
Perl or bash scripting? philipina Linux - General 1 07-26-2004 04:30 AM
question about perl scripting feetyouwell Linux - Software 2 02-13-2004 03:11 PM
shell scripting and perl irubin Programming 1 01-01-2004 08:27 AM
Perl scripting Rameriez Programming 4 02-03-2003 01:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:55 PM.

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