LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-18-2006, 04:53 AM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
simple bash variable command


Hello, I would like to enter 3 directories named CD1 CD2 and CD3 and I would like to get into each directory, preform this './../../../rar/rar e *.rar && rm -rf *.r* && cd ..'
in each directory.

I was doing something like this (got via ls -t the 3 directories I want)
but it's not working correctly
for i in 'ls -t | tail -4 | head -3' do 'cd $i && ./../../../rar/rar e *.rar && rm -rf *.r* && cd ..'
So help me fix the above command please!

there are 2 options to get this in loop one is this ls -t which I used here, but in case it's not by the same date and I want to do something like this for i=1 to 3 do cd CD$i

possible?


Thanks

Last edited by itz2000; 06-18-2006 at 05:35 AM.
 
Old 06-18-2006, 06:29 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
Quote:
I want to do something like this for i=1 to 3 do cd CD$i
Maybe using sequence would work...
Code:
for i in $(seq -w 1 3) ; do
cd CD$i
# do something here
ls
# go back to the main folder
cd ..
done
 
Old 06-18-2006, 08:02 AM   #3
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by homey
Maybe using sequence would work...
Code:
for i in $(seq -w 1 3) ; do
cd CD$i
# do something here
ls
# go back to the main folder
cd ..
done
Thanks,
here's the final command :
Code:
for i in $(seq -w 1 3) ; do cd CD$i; ./../../../rar/rar e *.rar; mv *.avi ../; rm -rf *.r*;  cd ..; done
THANKS!
 
Old 06-18-2006, 08:09 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
You're welcome!
 
Old 06-19-2006, 01:10 PM   #5
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Thanks!

I'd like to know where can I get a tutorial of these usuful things that will help me during my daily terminal usage?

things like

Code:
./program > file.txt
program &
for i in $(seq -w 1 3); do blabla; done
program1 && program2
 
Old 06-19-2006, 01:45 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
There are lots of goodies at http://www.tldp.org/LDP/abs/html/

I cruise up and down the linux forums like this one and google alot when looking for a particular idea.
 
Old 06-19-2006, 08:24 PM   #7
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by homey
There are lots of goodies at http://www.tldp.org/LDP/abs/html/

I cruise up and down the linux forums like this one and google alot when looking for a particular idea.
The problem is when I got no ideas on how to improve on my daily shell usage
but thanks for the link, from a firs 10 minutes review it look usful !
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bash, how to get variable name from variable Duudson Programming 6 01-06-2005 04:38 PM
Simple Bash Script Help Command kemplej Linux - Software 1 03-11-2004 03:52 AM
Bash script; command and args in variable. magjo813 Programming 2 02-16-2004 09:22 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 03:12 PM


All times are GMT -5. The time now is 09:14 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration