LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-20-2011, 02:28 PM   #16
isha
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled

Thank you very much for all your replies. I was reading all of them and taking what I needed. I fixed the bracket issue and @ grail. I was getting that error. I was just addressing the errors one at a time but I removed the space between the "=" and the path and it fixed the error "/home/me/homework/jpgfil is a directory". The only error I am getting is "Syntax error near the unexpected token `fi`.
If I was not clear. I need to find the jpg files in a directory specified by the user and move them to /home/me/homework/jpgfil and the copied files should have the date added to the name of the file. This is what I have so far.

#!/bin/bash

DATE=`date +%d-%m-%y`
dest=/home/me/homework/jpgfiles

read -p "What directory do you need to search?" dir
echo "Content of the directory being displayed"
ls $dir
read -p "what type of file do want to move?" tipo
if [ "$tipo"==jpg]
then
find $dir -name "*.jpg" -exec mv *.jpg $dest \;
elif
echo "Not supported search"
fi
-
-
-
 
Old 07-20-2011, 02:34 PM   #17
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
You did not specify a condition for "elif".

Also, use code tags when posting code.

And finally, do you want the "find" line to move all found files to "$dest"? If so, what you have won't work (see my previous post).

Last edited by MTK358; 07-20-2011 at 02:35 PM.
 
Old 07-20-2011, 07:04 PM   #18
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Code:
if [ "$tipo"==jpg]

# try this
if [[ "$tipo" == jpg ]]
for operators like '==' in a test statement, spaces are reqd

do read those links in my prev post and try the debug cmd I supplied
 
Old 07-20-2011, 09:24 PM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,425

Rep: Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826Reputation: 2826
I would suggest investigating the following line as well:
Code:
find $dir -name "*.jpg" -exec mv *.jpg $dest \;
As this is homework, my advice here is to go and look at more of your examples and check what you are trying to do here.

I would also agree with Chris that you need to look at some of the links he provided and have a look at quoting.
 
Old 07-20-2011, 09:25 PM   #20
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by chrism01 View Post
for operators like '==' in a test statement, spaces are reqd
Also, it should be "=", not "==".
 
Old 07-21-2011, 01:21 AM   #21
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by MTK358 View Post
Also, it should be "=", not "==".
Either is allowed. == is less portable.
 
Old 07-21-2011, 01:24 AM   #22
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
And '==' is more obviously a test, not an assignment
 
  


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




All times are GMT -5. The time now is 01:23 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration