LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Need help with bash scripting (http://www.linuxquestions.org/questions/linux-software-2/need-help-with-bash-scripting-443140/)

Kleedrac 05-09-2006 11:06 AM

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

raskin 05-09-2006 11:47 AM

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

Is idea clear?

rickh 05-09-2006 11:48 AM

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.

Kleedrac 05-09-2006 11:53 AM

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

David the H. 05-09-2006 11:54 AM

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

raskin 05-09-2006 11:57 AM

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 02:55 PM

Bash guide for Beginners--by Machtelt Garrels (on tldp.org)

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


All times are GMT -5. The time now is 04:36 PM.