Homework questions
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
|
Hi, welcome to LQ!
And here's a good place. Cheers, Tink |
find + -exec + if
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" #!/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 find $dir -name "*.jpg" -exec mv *.jpg $dest\; elif echo "Extension not supported" fi |
Quote:
The problem is the missing space between $dest and \; May I suggest that you put code tags around your code? Cheers, Tink |
What do you mean by code tags?,. I put left the space now I am getting.
" syntax error near unexpected token 'fi' |
this probably isn't related to the problem you posted, but I think you want to use "\{\}" instead of "*.jpg" in your exec section.
|
I made that change in the -exec section "\{\}" instead of "*.jpg" but that did not stop th "fi" error
|
I think you need a newline between elif and the echo command, that should fix your fi problem.
|
You've got mismatched bracket/braces here
if ["$tipo"==jpg}; I leave the answer up to you, but you're close... |
Quote:
You need to use square braces instead of curly braces. Late post, needed to reload the page. |
Quote:
proper formatting. To get code tags you put this PHP Code:
Quote:
Code:
#!/bin/bash |
Lots of good tips there; here's some good links to bash programming tutorials/docs
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ One thing I'd recommend for debugging is Code:
set -xv |
I would add that I am surprised your script gets as far as it does before presenting an error as the following:
Code:
dest= /home/me/homework/jpgfil Code:
./script.sh: line 3: /home/me/homework/jpgfil: is a directory |
Also, don't use backticks, use $(command) instead. It nests easily and can't be confused with commas.
It only works with bash (not plain sh), but I see that you're using bash anyway. |
Quote:
Quote:
Quote:
Quote:
Quote:
http://mywiki.wooledge.org/BashPitfa...22.24foo.22.5D Quote:
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. |
All times are GMT -5. The time now is 06:38 AM. |