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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-09-2006, 11:06 AM
|
#1
|
Member
Registered: Apr 2004
Location: Saskatoon SK. CA
Distribution: Ubuntu Dapper
Posts: 50
Rep:
|
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
|
|
|
05-09-2006, 11:47 AM
|
#2
|
Senior Member
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
|
man bash
for i in *.sh; do
cat $i;
done
Is idea clear?
|
|
|
05-09-2006, 11:53 AM
|
#4
|
Member
Registered: Apr 2004
Location: Saskatoon SK. CA
Distribution: Ubuntu Dapper
Posts: 50
Original Poster
Rep:
|
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 
|
|
|
05-09-2006, 11:54 AM
|
#5
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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
|
|
|
05-09-2006, 11:57 AM
|
#6
|
Senior Member
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
|
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.
|
|
|
05-09-2006, 02:55 PM
|
#7
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
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:12 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|