Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm terrible with bash scripting, and need some help with the following:

#!/bin/bash

if [ -e Pretty* ];then
ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 /home/xbmc/TV/Pretty_Little_Liars/ Pretty*
else
echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;

Problem here is the ncftpput line.. if I just do a simple [ echo "working" ] instead, everything is OK, but when I try the ncftpput-line it just gives me [ line 5: [: too many arguments ]

the ncftpput command alone works fine..

Any ideas?

share|improve this question

migrated from serverfault.com Feb 6 '11 at 17:52

This question came from our site for system and network administrators.

    
I'm pretty sure "how to copy around my pirated TV" is off topic for this site. Not on moral grounds or anything; it's just out of scope. –  mattdm Feb 6 '11 at 15:24
1  
It's actually "how to copy new recordings from my networked pvrbox to my media center" ;) –  eple Feb 6 '11 at 16:05
    
The assumption that everything is always illegal is tiresome. :( Aside from all else, not every has the same laws. –  Sirex Feb 8 '11 at 14:54

3 Answers 3

up vote 4 down vote accepted

You can't use globbing with -e inside [] because it's likely to return more than one result which will give you a too many arguments error.

You can try:

shopt -s nullglob
if [[ -n "$(echo Pretty*)" ]]

or

if [[ "$(echo Pretty*)" != "Pretty*" ]]

Also, use indenting, spaces and line continuation to make your code more readable:

#!/bin/bash

shopt -s nullglob
if [[ -n "$(echo Pretty*)" ]]; then
    ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 \
        /home/xbmc/TV/Pretty_Little_Liars/ Pretty*
else
    echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;
share|improve this answer
    
Thank you soo much! That was it :) And I learned something new today too! –  eple Feb 6 '11 at 15:26
    
This question was migrated due to it being just a scripting question. There are lots of other bash scripting questions that exist on Super User. –  Troggy Feb 7 '11 at 15:50
    
@Troggy: There are lots of scripting questions on SO. Perhaps they should be moved en masse and banned. ;) –  Dennis Williamson Feb 7 '11 at 15:56

Try it.

#!/bin/bash -x

if [ -e "Pretty*" ];then
`ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 /home/xbmc/TV/Pretty_Little_Liars/ Pretty*`
else
echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;
share|improve this answer
    
Thanks for trying, but that doesn't work :( When it is written like that the wildcard (*) doesn't match anything. –  eple Feb 6 '11 at 13:00
    
Weird... If I use "" in (if [ -e "Pretty*" ];then it doesn't give me a "too many arguments" error, but * don't work as a wildcard.. –  eple Feb 6 '11 at 13:08

Well, if it's complaining of too many arguments, break it with a for.

#!/bin/bash

if [ -e Pretty* ];then
   for FILE in Pretty*
   do
       ncftpput -R -DD -v -u xbmc -p xbmc 192.168.1.100 /home/xbmc/TV/Pretty_Little_Liars/ "$FILE"
   done
else
   echo "No new folders"
fi

find -depth -type d -empty -exec rmdir {} \;

Using the "" around $FILE will ensure that files with spaces on their name don't do anything unexpected.

share|improve this answer
    
This one is also complaining about too many arguments. If it matters: Pretty* is several folders with different names, all starting with "Pretty" None of the folder have spaces in them.. –  eple Feb 6 '11 at 13:14
    
Run the ncftpput line (with all your options) plus a folder name and see if it gives you the same error. I am not familiar with ncftpput but seems to be something wrong with that line. –  coredump Feb 6 '11 at 13:27
    
The ncftpput line alone works just fine, no errors, and it's does what's expected. –  eple Feb 6 '11 at 13:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.