LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash script. help needed (https://www.linuxquestions.org/questions/linux-general-1/bash-script-help-needed-368032/)

tazthecat 09-29-2005 02:03 AM

Bash script. help needed
 
hello,

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

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 ? :confused:

Thanks in advance..
Tazthecat

flower.Hercules 09-29-2005 07:49 AM

File test operators

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

Good luck!

tazthecat 09-30-2005 01:54 AM

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......


All times are GMT -5. The time now is 07:27 AM.