LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-09-2006, 11:06 AM   #1
Kleedrac
Member
 
Registered: Apr 2004
Location: Saskatoon SK. CA
Distribution: Ubuntu Dapper
Posts: 50

Rep: Reputation: 15
Unhappy Need help with bash scripting


Hey all,

I'm essentially looking for a quick-n-dirty scripting intro and then I should be good, I have coded in java, perl, c, and others but it's been a while and I've never really got into shell scripting. Essentially I'm trying to write a script to execute one command on each file in a directory. Basic file conversion at its finest, I'm just hoping I can write this script quickly before it becomes necessary to convert each file manually Come to think of it all I really need is to tell the script to find all files of a given type in the current directory and construct a loop to go through them Thanks for your time

Kleedrac
 
Old 05-09-2006, 11:47 AM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
man bash
for i in *.sh; do
cat $i;
done

Is idea clear?
 
Old 05-09-2006, 11:48 AM   #3
rickh
Senior Member
 
Registered: May 2004
Location: Albuquerque, NM USA
Distribution: Debian-Lenny/Sid 32/64 Desktop: Generic AMD64-EVGA 680i Laptop: Generic Intel SIS-AC97
Posts: 4,250

Rep: Reputation: 62
I've been working on something similar.

Here's a thread with me getting help.

And a couple internet links that I found helpful,
http://6v8.gamboni.org/Mass-renaming...nux-shell.html

http://www.arachnoid.com/linux/shell_programming.html

The second internet link there is kind of a 'jump in the deep water' quickly intro to bash scripting. I got a lot of usful things there.
 
Old 05-09-2006, 11:53 AM   #4
Kleedrac
Member
 
Registered: Apr 2004
Location: Saskatoon SK. CA
Distribution: Ubuntu Dapper
Posts: 50

Original Poster
Rep: Reputation: 15
Woah ... all right ... thanks guys.
Raskin: So if I understand right if I just wanted to duplicate every file of type .sh in a directory;

for i in *.sh; do
cp $i $i.nosh
done

Is that basically it?! Man ... thanks a lot you guys ... I'll try this out when I'm done work today
 
Old 05-09-2006, 11:54 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I found this "quick & dirty' intro to be very useful. If you've done programming before, it should be a snap for you.LinuxCommand.org

For more in-depth study, try here:

Advanced Bash Scripting Guide
 
Old 05-09-2006, 11:57 AM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Yes, if you haven't .sh.nosh files it will work fine. Else it'll work fine, but destroy information. Also, if you add suffix ${i}.nosh is more predictable if some day you suffix will try to merge with variable name - that way it is delimited.
 
Old 05-09-2006, 02:55 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Bash guide for Beginners--by Machtelt Garrels (on tldp.org)

Classic shell scripting--O'Reilly Most any big bookstore or Amazon
 
  


Reply

Tags
script, shell



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
help bash scripting sh4d0w13 Linux - Newbie 5 08-15-2005 02:02 AM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 04:09 AM
BASH Scripting ? eroica Programming 3 06-07-2004 07:51 PM
Bash scripting JonCooperUK Programming 3 03-04-2004 08:55 PM
About bash scripting pazvant Programming 3 10-20-2003 11:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:25 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