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

Pages: 1-4041-

BASH scripting

Name: Anonymous 2009-09-08 13:25

sup
i'm using "read" to get a directory path into an env variable.
shit works well when the path doesn't contain an escape command for whitespaces like here:
/home/durp/pics/test_folder/
this here makes problems:
/home/durp/pics/test\ folder/
"read" simply ignores the escape command, but i need it. how do i circumvent that?

Name: Anonymous 2009-09-08 13:26

>>1
Well, for a start, you shouldn't be using spaces in your filenames

Name: Anonymous 2009-09-08 13:30

>>2
well, that's not an option for me.

Name: Anonymous 2009-09-08 13:39

RTFM noob

Name: Anonymous 2009-09-08 13:39

Use Perl to recursively replace all the spaces in your directory names with underscores or dashes (as suits your fetishes).
Then your script will work *and* you won't have spaces in your directory names (that's big fail right there, kid, big fail)

Name: Anonymous 2009-09-08 13:41

>>1
Don't use Bash!  Use C!

Name: Anonymous 2009-09-08 13:42

>>3
I'm curious as to why

I don't see anything in the man page, but have you tried using a sed script to transform the ' 's into '\ 's?

Name: Anonymous 2009-09-08 13:56

>>7
oh pls, it looks like shit with underscores. that's why. i want to keep my whitespaces...

Name: Anonymous 2009-09-08 13:57

looks
like
shit

Oh please tell me that not the only reason you persist in such failure?

Name: Anonymous 2009-09-08 13:57

This is not MS_DOS. Shun the underscored.

Name: Anonymous 2009-09-08 13:58

>>10
This is most likely my worst post ever. :(

Name: Anonymous 2009-09-08 14:00

>>11
with >>8 close on it's heels

Name: Anonymous 2009-09-08 14:01

>>11
Then why did you post it?

>>8
Are you by any chance the same person who suggested a while back, that names should be allowed to have spaces and that they should be delimited by two spaces?

Name: Anonymous 2009-09-08 14:05

>>13
Then why did you post it?
I was typing fast OK!

Name: Anonymous 2009-09-08 14:23

>>1
read treats a backslash as a escape character. There's an option for read which makes the character act as part of the line but I don't want to deny you the learning experience of Reading The Fucking Manual.

>>2
Bullshit. White-spaces in file names are a not an issue. Opinions held as truths are. One man good practice is another's shitty design.

Name: Anonymous 2009-09-08 14:27

shitty design
Like the use of whitespace in directory names, verily.

Name: Anonymous 2009-09-08 14:33

why the fuck are you using read? sounds like shit design

Name: Anonymous 2009-09-08 15:10

>>10
I used 0xFF as whitespace in MS DOS. Confused the shit out of people.

Name: Anonymous 2009-09-08 15:12

>>16
It's a legal character as any other. If a script brakes because it can't handle a legal character then the script is shit. Sorry mate.

Not that it matters for one-off script.

Name: Anonymous 2009-09-08 15:23

If a script brakes
brakes

Slow down there Andretti.

Just because it's a legal char. does not mean its The Right Way to do it, or even an advisable or smart way to do it either. Since it obviously breaks shit why do it, deeeeeeeeerp

Name: Anonymous 2009-09-08 15:30

Don't forget to make sure your script handles filenames with newlines in them.

Name: Anonymous 2009-09-08 15:42

>>21
Not this is just plain rude, sir! Newlines are escape sequences, not characters like spaces.

Name: Anonymous 2009-09-08 15:55

>>20
The smart way would be to call read a single option and it will support Wapanese file names. It's not really an issue. If white space is an issue then you either have to migrate from DOS or read the fucking manual.

>>21
And null string termination.

Name: Anonymous 2009-09-08 17:08

shit works now, but now i have another problem:
the path with the escaped whitespaces is in my $var
if i do ls $var it fails
if i do ls /home/durp/pics/test folder/ it works, but there's actually no difference between the $var and /home/durp/pics/test folder/
so what the fuck is wrong now?

Name: Anonymous 2009-09-08 17:13

>>24
try ls "$var"

Name: Anonymous 2009-09-08 17:16

>>25
tried that already:
ls: /home/durp/pics/test folder/: No such file or directory

:(

Name: Anonymous 2009-09-08 17:17

>>24
correction, it's of course:
/home/durp/pics/test\ folder/

Name: Anonymous 2009-09-08 17:19

don't forget about filenames that start with '-', or have '*' or '?' in them...

Name: Anonymous 2009-09-08 17:25

#!/bin/bash

var=/home/durp/pics/test\ folder/

ls $var
ls /home/durp/pics/test\ folder/


first one fails, second one not, what the hell?

Name: Anonymous 2009-09-08 17:27

maybe im being incredibly dumb here, but try setting $var as /home/durp/pics/test\\\ folder/

Name: Anonymous 2009-09-08 17:28

>>29
see >>25.
also, what non-standard shit are you using that you need bash instead of /bin/sh?

Name: Anonymous 2009-09-08 17:30

>>30
nope still getting this:
ls: /home/durp/pics/test\: No such file or directory
ls: folder/: No such file or directory

Name: Anonymous 2009-09-08 17:32

>>31
>see >>25.
see >>26

well, because i can? why should i use /bin/sh?

Name: Anonymous 2009-09-08 17:33

>>32
well duh do ls "$var"

Name: Anonymous 2009-09-08 17:35

>>34
oh lawd...

Name: Anonymous 2009-09-08 17:36

>>33
because /bin/sh is available everywhere. only faggots have bash installed.

Name: Anonymous 2009-09-08 17:39

>>36
only faggots are using sh instead of bash or zsh.
fuck them

Name: Anonymous 2009-09-08 17:48

INTERNET ARGUMENT time!
>>36
You're wrong!
>>37
Faggot!
>>34
You have no fucking idea, I know better!
>>39
Fuck you!

Name: Anonymous 2009-09-08 17:48

>>37
everyone who isn't a faggot uses zsh. but they still have /bin/sh.
just like everyone uses vi, but still has ed.
only faggots have things like bash and vim installed.

Name: Anonymous 2009-09-08 18:01

>>39
Excellent point!

Name: Anonymous 2009-09-08 18:03

>>39
Medication time gramps. Sit down in your wheelchair or you'll brake a hip again.

Name: don't forget your sage 2009-09-08 18:22

INTERNET ARGUMENT time!
>>36
You're wrong!
>>37
Faggot!
>>34
You have no fucking idea, I know better!
>>39
Fuck you!

Name: Anonymous 2009-09-08 21:09

>>33
see >>29
Quote your shit and keep it quoted. I just tested your program with quotes around var and it worked. Also, use sh like a real man.

Name: Anonymous 2009-09-08 21:44

>>43
you troll me? shits not working...

Name: Anonymous 2009-09-08 21:47

I use bash. end thread.

Name: Anonymous 2009-09-08 22:01

>>44
No. Here is the code (different file path):
[code]
#!/bin/sh
var=$HOME/Documents/temp/theres\'\ a\space/

ls "$var"
ls $HOME/Documents/temp/theres\'\ a\space/
[\code]
Prints out fine.

Name: Anonymous 2009-09-08 22:02

>>47
Bah. New here. Haven't learned to BBCode. Also a space inbetween "a\" and "space"

Name: Anonymous 2010-12-25 13:54

<

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