Monday, January 19, 2015

Re: [LINUX_Newbies] Help with script and regex.

 

On 19Jan2015 18:20, J <dreadpiratejeff@gmail.com> wrote:
>Snipped everything but part of Cameron's reply because that's what I'm
>really commenting about (though the comment is directed at the OP, not
>Cameron)
>
>On Mon, Jan 19, 2015 at 5:54 PM, Cameron Simpson cs@zip.com.au
>[LINUX_Newbies] <LINUX_Newbies@yahoogroups.com> wrote:
>
>> {2009}«{12}«{04}«{PHOTOS}«{Pictures}
>
>I'm kinda curious about why the need for {} and << in a file name and
>path? Given that in BASH and DASH, at least, both are special shell
>characters, right?

The "«" is a _single_ character, not the "<<" redirection syntax associated
with here-documents. If the OP can type it easily (I'm using cut/paste myself)
it is entirely reasonable.

The { and } are not particularly special. In modern shells, {...,...} _is_
special as it performs enumeration eg foo{this,that}bah turning into
"thisfoothat" and "thisbarthat". However, it is _not_ special otherwise.

For example, the find command's placeholder argument:

find . -type f -name '*foo*' -exec echo found foo named {} ';'

does not need any escaping on the shell command line for the {}; it has been so
for decades.

>Because to type that out on a shell (which you'd need to do in most
>scripts, right? maybe not in python, perhaps, but anything that is
>done in shell) you'd need to escape all that, and end up looking like
>this when typed in manually:
>
># \{2009\}|\<\<\{12\}\<\<\{04\}\<\<\{PHOTOS\}\<\<\{Pictures\}

Really, you don't need to escape _any_ of this at a normal shell prompt.

(Besides, with names that long one would normally use file completion:-)

>Even in sed or awk, I believe you'd need to escape all that, I think.

Nope. Nothing special there.
>Personally, my photos are all categorized more descriptively (and more
>shell friendly for times when I need to use a shell script on one or
>more directories and filenames:
>
>/Photography/2014/2014-04-25_Some_Event/raw/2014-04-25_Some_Event-001.raw
>/Photography//2014/2014-04-25_Some_Event/processed/2014-04-25_Some_Event-001.jpg

Out of curiosity, do you use any specific tools to manage these?

>Anyway, point is, if you want to use shell scripts on things, it
>really pays to not use special shell constructs in the naming
>convention.

Not if the shell scripts are written robustly. You really shouldn't need to
care much about the contents of filenames.

That said, personally I avoid whitespace, slashes, and a lot of shell
punctuation such as "(", ";" etc. (But not "{" so much.)

I even have handy scripts to fold hated filenames into saner filenames, such as
my "__" script:

https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/__

which wraps frename:

https://bitbucket.org/cameron_simpson/css/src/tip/bin/frename

Ah, such fun...

>But that's just my opinion...

Cheers,
Cameron Simpson <cs@zip.com.au>

In My Egotistical Opinion, most people's C programs should be indented six
feet downward and covered with dirt. - Blair P. Houghton

__._,_.___

Posted by: Cameron Simpson <cs@zip.com.au>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (6)
To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.

.

__,_._,___

No comments:

Post a Comment