-   Linux - Software (
-   -   Need help with bash scripting (

Kleedrac 05-09-2006 12:06 PM

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 :)


raskin 05-09-2006 12:47 PM

man bash
for i in *.sh; do
cat $i;

Is idea clear?

rickh 05-09-2006 12:48 PM

I've been working on something similar.

Here's a thread with me getting help.

And a couple internet links that I found helpful,

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.

Kleedrac 05-09-2006 12:53 PM

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

Is that basically it?! Man ... thanks a lot you guys ... I'll try this out when I'm done work today :)

David the H. 05-09-2006 12:54 PM

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

For more in-depth study, try here:

Advanced Bash Scripting Guide

raskin 05-09-2006 12:57 PM

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.

pixellany 05-09-2006 03:55 PM

Bash guide for Beginners--by Machtelt Garrels (on

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

All times are GMT -5. The time now is 02:09 PM.