Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Disregard spaces, aquire full paths [bash]

Name: Anonymous 2009-11-28 16:25

So, like, guise, I have this bash script that `find`s all of the images in a directory and performs a task on them, but shit goes down when the path has spaces in it.

Like, say I have a path ~/blah.jpg, it performs the task on ~/blah.jpg, but if I have shit like ~/blah 2.jpg, it tries to do it to ~/blah and 2.jpg, which sucks total ass.

How can I fix dat shit, my /prog/ niggas?

Inb4 "Herp derp spaces in unix".

Name: Anonymous 2009-11-28 16:32

use Perl;

Name: Anonymous 2009-11-28 16:46

Back to /b/, please

Name: Anonymous 2009-11-28 17:21

path="\"$path\""

Name: Anonymous 2009-11-28 17:27

THIS IS WHY I USE XARGS

Also, Herp derp spaces in unix

Name: Anonymous 2009-11-28 17:28

>>1
This is why I always use _'s

Name: Anonymous 2009-11-28 17:29

>>6
This is why I always use superfluous apostrophe's.

Name: Anonymous 2009-11-28 17:29

Shit, I'm fucking stupid.

It's this fucking for loop I've got that's fucking with the spaces.

I've got like


for i in `find -name ".jpg" -o -name "*.png"`


And it's reiterating for the spaces. Can I make it only do it for the newlines instead of just any whitespace? The whole thing is I'm not good at bash and its a nigger when it comes to strings anyways.

Name: Anonymous 2009-11-28 17:35

>>8
Whose a nigger?

Name: Anonymous 2009-11-28 17:36

>>7
Yeah, I have no idea why I did that
>>8
I don't think it can check for names like that, but you could use -print0 and a pipe or something I don't actually know or care

Name: Anonymous 2009-11-28 17:40

XARGS

Name: OP 2009-11-28 17:53

Fixed it with the $IFS variable.

Kthxbye.

Name: Anonymous 2009-11-28 19:35

And of course, if you've been following along for a week or two, you know that this (BING!) is a Useless and Dangerous Use of Backticks!
Remember, most cases where you have:
    for f in `command ...`; do
        ...
    done

you should rewrite it as:
    command ... |
    while read f; do
        ...
    done

and in some cases, such as this one, you can use xargs as in:
    find ... -print0 | xargs -0 foo

Just another Useless Use of /prog/,

Name: Anonymous 2009-11-28 19:39

perl

Name: Anonymous 2009-11-28 20:01

>>13
>and in some cases, such as this one, you can use xargs as in:

Lolno. If you knew what I was doing that'd be like trying to swallow thumbtacks. Go shove a dildo down your throat, you fucking tool.

Name: Anonymous 2009-11-28 22:11

>>14
Useless Use Of Perl, bro. Fight the power.

Name: Anonymous 2009-11-28 22:29

XARGS == CORRECT

Don't change these.
Name: Email:
Entire Thread Thread List