LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 09-29-2005, 02:03 AM   #1
tazthecat
LQ Newbie
 
Registered: Feb 2005
Distribution: Fedora Core 3
Posts: 5

Rep: Reputation: 0
Bash script. help needed


hello,

I've written my first bash script but I ran into some problems.

Quote:
#!/bin/bash

ls -1A -- *.rar | while read FILE
do
echo "Doing file $FILE..."
unrar x "$FILE"
done
ls -1A -- *.avi | while read FILM
do
echo "Moving file $FILM..."
mv "$FILM" /home/tazthecat/films/"$FILM"
done
works, but only if the rar file is named *.rar, *.r01, etc.
If the filename is *.part1.rar, *.part2.rar, etc. it keeps extracting the file over and over again.
How do I tell script to stop if $FILE exist ?

Thanks in advance..
Tazthecat
 
Old 09-29-2005, 07:49 AM   #2
flower.Hercules
Member
 
Registered: Aug 2005
Distribution: Gentoo
Posts: 228

Rep: Reputation: 31
File test operators

It is part of a larger Guide: Advanced Bash-Scripting Guide

Good luck!
 
Old 09-30-2005, 01:54 AM   #3
tazthecat
LQ Newbie
 
Registered: Feb 2005
Distribution: Fedora Core 3
Posts: 5

Original Poster
Rep: Reputation: 0
thanks flower.Hercules for your response.

I have found out that instead of 'rar x *.rar' 'rar x -o- *.rar' -o- is to stop if file exists.

Here is another script I wrote to sort my download folder.

Quote:
#!/bin/bash

ls -1A -- *.zip *.rar *.gz *.bz2 2>/dev/null | while read RAR; do
echo "Moving file $RAR..."
mv -- "$RAR" /home/tazthecat/zip_bestanden/
done

ls -1A -- *.jpg *.jpeg *.gif 2>/dev/null | while read AFB; do
echo "Moving file $AFB..."
mv -- "$AFB" /home/tazthecat/Afbeeldingen/
done

ls -1A -- *.bin *.rpm *.sh *.run 2>/dev/null | while read EXE; do
echo "Moving file $EXE..."
mv -- "$EXE" /home/tazthecat/installers/
done

ls -1A -- *.doc *.sxw *.txt 2>/dev/null | while read TXT; do
echo "Moving file $TXT..."
mv -- "$TXT" /home/tazthecat/tekst_bestanden/
done
I have this file in ~/.gnome2/nautilus-scripts/ just change dir's to match your dir's. rightclick choose name of script.

Scripting is still hard for me, but I try try again......
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script help needed Henster Linux - General 4 08-21-2005 09:54 AM
Wrapper needed for BASH Script outspoken Programming 0 01-12-2005 09:04 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM


All times are GMT -5. The time now is 07:43 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