LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2008, 12:03 AM   #1
tommytomthms5
Member
 
Registered: Sep 2007
Distribution: debian based
Posts: 308

Rep: Reputation: Disabled
fun shell scripts


im trying to get a grasp on how to make shell scripts...

my current experiment is to take for example folder ./1 has 25 files 1.examp 2.examp 3.exap.... and so on

i wanna just for the hell of it take each file and make 1000 copies of it...

so in the end folder ./1 will have 25,025 files in it (dont forget the original 25...)

heres my thoughts

Code:
#start with a

i=1 #as in i is an integer equal to 1

IFS=$'\n' # ignore spaces in files

let i++ # makes integer go up in numbers

if [ i<25000 ] # if integer i is less then 25000 (25 files times 1000)

then cp ./*.examp $(printf "%01d"$i).examp # copy all .examp files to 0(number_that_integer_equals).examp 

else echo "finished" # when done tell me

fi #close loop

done # close operation
but it dosen't quite work like that...

Last edited by tommytomthms5; 07-12-2008 at 12:04 AM. Reason: simple spelling error
 
Old 07-12-2008, 06:46 AM   #2
kummiliim
Member
 
Registered: Mar 2007
Location: Tallinn, Estonia
Distribution: Slackware 12.0
Posts: 276

Rep: Reputation: 30
for i in $(ls 1);do a=0;while [ "$a" -ne "1000" ];do cp "1/$i" "1/$i-copy-$a";let a++;done;done

: )
 
Old 07-12-2008, 06:57 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Or slightly shorter notation: "for ((i=1;i<10;i++)); do doSomethingWith${i}; done".
 
Old 07-12-2008, 08:02 AM   #4
tommytomthms5
Member
 
Registered: Sep 2007
Distribution: debian based
Posts: 308

Original Poster
Rep: Reputation: Disabled
can you break down the code so i learn it thats the point not to run it
 
Old 07-12-2008, 08:15 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by tommytomthms5 View Post
can you break down the code so i learn it thats the point not to run it
Time for a book. I would start with Bash Guide for Beginners by Machtelt Garrels---free at http://tldp.org

To give you a head start, the example given is a "for loop"--one of many kinds of loops that are a staple of any programming language. In Bash, the basic syntax is:

for <conditions>; do
<task1>
<task2>
<task3>
.
.
done

"conditions" can be a variety of things. In the 1st example, the construct:
for i in $(ls 1)
translates as follows:
run the ls command on the directory "1"
take this list and iterate through it, assigning each successive filename to the variable "i"

In this case, the loop finishes simply when it reaches the end of the list.
 
  


Reply



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
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
Shell scripts shmuel_orgad Programming 4 05-21-2006 05:33 AM
Need help with shell scripts thorney Linux - Newbie 4 11-27-2005 11:18 PM
Shell scripts anon227 Linux - Software 1 01-03-2003 03:11 PM
shell scripts nautilus_1987 Linux - General 3 08-30-2002 03:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:24 AM.

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