LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   stupid shell moans about spaces.... (https://www.linuxquestions.org/questions/linux-software-2/stupid-shell-moans-about-spaces-575758/)

trscookie 08-08-2007 08:56 PM

stupid shell moans about spaces....
 
can someone please amend this code so it would work, I have tried everything :'(

Code:

for i in *; do mv $i `echo "$i" | tr '[A-Z]' '[a-z]'`; done
mv: target `funnier.jpg' is not a directory
mv: `original.jpg' and `original.jpg' are the same file


thanks, trscookie

gilead 08-08-2007 09:07 PM

I haven't tested it but have you tried wrapping your first $i in double quotes - e.g. "$i"? Also, have a look here at http://www.linuxquestions.org/questi....php?p=2810545 for a similar question.

pixellany 08-08-2007 10:09 PM

The shell is not stupid.....it's not smart enough to be stupid. Your example doesn't show it, but the title implies that you have some file names with spaces (bad).

If you have a file name with a space, see what happens when to just try to rename that one file---eg:
mv this file newname
vs
mv "this file" newname

trscookie 08-08-2007 10:11 PM

Ok how about this:


how do I return what the name of the current folder I'm in?

for example:

if you run pwd it returns the full path I just want to return the last folder that I entered?

Cheers again.

pixellany 08-08-2007 10:33 PM

pwd | sed 's,^.*/,,'

(I'm sure there's some other way, too....)

trscookie 08-08-2007 10:38 PM

thanks, I could never get to grips with sed

pixellany 08-09-2007 08:04 AM

Quote:

Originally Posted by trscookie
thanks, I could never get to grips with sed

http://www.grymoire.com/Unix/Sed.html#uh-8
Best tutorial I have seen to date.....

theYinYeti 08-09-2007 08:52 AM

Code:

/bin/ls -1 *[A-Z]* | while read i; do mv "$i" "$(tr '[A-Z]' '[a-z]' <<<"$i")"; done
or recursive:
Code:

find . -depth -name '*[A-Z]*' -print | while read i; do mv "$i" "$(tr '[A-Z]' '[a-z]' <<<"$i")"; done
Yves.

theYinYeti 08-09-2007 08:54 AM

Quote:

Originally Posted by trscookie
how do I return what the name of the current folder I'm in? [...] I just want to return the last folder that I entered?

Code:

basename "$PWD"
Yves.


All times are GMT -5. The time now is 06:21 AM.