|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
mv using variables
Hi I am trying to write a script that will do a test on a file name, and then move files in batches to newly created directories. For now I am testing it by having the script search for a single file. Everything seems to work (the script does create the directories) but can't get the file to actually move! Can anyone tell me what is wrong with the indicated line? Thanks! I am on a MacBook and here is the script:
#!/bin/sh filecount=1 mkdir $filecount for FILE in $DSC* do if [ $FILE != "test.sh" ] then if [ $FILE = "DSC03278.JPG" ] mv $FILE $filecount #I think my problem is here else #bumps filecount - will later be used to skip over marker shots let "filecount=filecount + 1" #mkdir $filecount fi fi done |
| Sponsored Links |
|
|
|
|||
|
scottn believe it or not - you did fix it! It was sloppy code that was tripping it up. I am trying to run this for a group of files (the parameters for the IF will soon change once I figure out a bit of python) - so I called it a batch. The current IF was just an easy way to do a proof of concept for the rest of the code. Out of curiosity: what if I wanted to make the if statement wild? For instance: Code:
if [ $FILE = "DSC0328*" ]?? I know this is wrong because it will treat * as part of the string, but I can't figure out the right combo. Thanks again! |
|
||||
|
You don't really need the "if" at all. The for-loop will give you all the DSC* files. Code:
$ touch DSC1 DSC2 BLAH DSC3 $ ls -l -rw-r--r-- 1 scott staff 0 Dec 5 02:28 BLAH -rw-r--r-- 1 scott staff 0 Dec 5 02:28 DSC1 -rw-r--r-- 1 scott staff 0 Dec 5 02:28 DSC2 -rw-r--r-- 1 scott staff 0 Dec 5 02:28 DSC3 $ for FILE in DSC*; do > echo $FILE >done DSC1 DSC2 DSC3 |
|
|||
|
Right! Much newbie thanks!
|
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to convert byteArray variables to HexaString variables for Linux? | ritesh_163 | Programming | 2 | 08-11-2008 12:55 AM |
| naming variables with variables | Allasso | Shell Programming and Scripting | 2 | 06-27-2008 11:45 AM |
| variables | fwabbly | UNIX for Dummies Questions & Answers | 4 | 07-25-2007 09:59 AM |
| using variables in sed | bishweshwar | UNIX for Advanced & Expert Users | 1 | 06-07-2007 09:47 AM |
| Variables | gina | UNIX for Dummies Questions & Answers | 3 | 06-04-2007 10:07 AM |