Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am writing a script from an assignment in my Linux class and I am having problems. Where can I post my script to get suggestions about what could be wrong
so my homework is to find the jpg files in a folder specified by the user and move them to another folder with the date added to the filename. I have not gotten to the name change part. I need to fix this first.
this is my script and I am having an error " -exec missing argument"
read -p " what directory do you want to search?" dir
echo " Listing directory content"
ls $dir
read -p "what type of file are you looking for?" tipo (this is just an extra question, it is not needed because he wants the script only for jpg files)
if ["$tipo"==jpg};
then
find $dir -name "*.jpg" -exec mv *.jpg $dest\;
elif echo "Extension not supported"
fi
so my homework is to find the jpg files in a folder specified by the user and move them to another folder with the date added to the filename. I have not gotten to the name change part. I need to fix this first.
this is my script and I am having an error " -exec missing argument"
read -p " what directory do you want to search?" dir
echo " Listing directory content"
ls $dir
read -p "what type of file are you looking for?" tipo (this is just an extra question, it is not needed because he wants the script only for jpg files)
if ["$tipo"==jpg};
then
find $dir -name "*.jpg" -exec mv *.jpg $dest\;
elif echo "Extension not supported"
fi
The problem is the missing space between $dest and \;
May I suggest that you put code tags around your code?
Code tags make code easier to read by maintaining
proper formatting. To get code tags you put this
PHP Code:
[CODE][/CODE]
around the piece of code. See the effect below.
Quote:
I put left the space now I am getting.
" syntax error near unexpected token 'fi'
Sorry, no idea what "I put left the space" implies.
Code:
#!/bin/bash
DATE=`date +%d-%m-%y`
dest= /home/me/homework/jpgfil
read -p " what directory do you want to search?" dir
echo " Listing directory content"
ls $dir
read -p "what type of file are you looking for?" tipo #(this is just an extra question, it is not needed because he wants the script only for jpg files)
if ["$tipo"==jpg};
then
# your line
find $dir -name "*.jpg" -exec mv *.jpg $dest\;
# correct line
find $dir -name "*.jpg" -exec mv *.jpg $dest \;
elif
echo "Extension not supported"
fi
read -p " what directory do you want to search?" dir
echo " Listing directory content"
read -p "what type of file are you looking for?" tipo (this is just an extra question, it is not needed because he wants the script only for jpg files)
Why are you putting spaces in front of the strings you're printing? And if they're intentional, why is there not one in the last line in the above snippet?
Quote:
Originally Posted by isha
Code:
ls $dir
Always put quotes around variables that contain filenames, since otherwise it will be split into separate arguments if the filename has spaces.
Quote:
Originally Posted by isha
Code:
if ["$tipo"==jpg};
then
The "[" syntax is not some kind of expression, it's a command. That means that there have to be spaces between the arguments. Also, it should be a square bracket at the end, and the semicolon is not needed since there already is a newline before the "then".
Again, put quotes around variables that contain filenames. Anyway, there should be a space between "$dest" and "\;".
Also, what is will do is attempt to copy all "*.jpg" files in the current directory into "$dest" every time "find" comes across a matching file. I don't think that's what you want. Even if that's what you want, if a filename you want to copy happens to contain "{}", find will replace it with the current filename that it found.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.