Re: splitting words into individual characters
On 2006-11-03, Mitch wrote:
> Hello again.
>
> I'm still learning, but a lot of it I am finding through reading the
> groups and by asking Google nicely, however I have yet to find an answer
> to this one.
>
> I am trying to break a word down into individual characters. OK that's
> not true, I'm trying to break down the file permissions into individual
> sections.
>
> I've got ls -l filename | awk ' { print $1 } ' which works (I worked
> this out myself, so if there is an easier/better way of getting it, I'd
> appreciate it...) Its giving me what I think I want (-rw-r--r--) but I
> am trying to figure out how to break it down into individual letters. I
> have seen examples of "case in (?r*)" format but this would leave me
> with a lot of variations to consider when I am trying to translate the
> file permission string into a pretty table.
>
> so my question is, how can I change a word (-rw-r--r-- or equiv) into a
> list/array of individual characters.
set -- $( ls -l "$filename" | sed -e 's/ .*//' -e 's/./& /g' )
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
|