Register
It is currently Sun Sep 21, 2014 12:07 pm

Question on what a script is doing


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri May 10, 2013 12:31 pm   

Joined: Fri May 10, 2013 12:23 pm
Posts: 5
First off, I apologize in advance if this is the wrong place to post this question.

I am new to shell scripts. I understand that what I am trying to read is both Bash script and Regex.

I can't seem to separate where the Bash part ends and the regex begins. I was hoping someone here could explain what is going on at a Specific line in this script.

for file in ViewController.h EventObserver.h
do
if [ -f "$file" ];then
exec 4<"$file"
while read -r line
do
echo "$line"
case "$line" in
*"*"*)
line="${line/* \/*!/* *!}";; #this line here, I would like to know how to read it
esac
echo "$line"
done >t
exec 4<&-
mv t "$file"
fi
done


Please keep in mind that i know what the outcome of the line is. I am specifically asking how to read the line. I would be unable to create similar scripts if i can't understand the mechanics of this line.


Top
 Profile  
 PostPosted: Sun May 12, 2013 8:58 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 548
hi,

this
Code:
"${line/* \/*!/* *!}"
is not a regex.
this is Parameter Expansion (see man bash about ${parameter/pattern/string} ), it uses special pattern characters (see Pathname Expansion - Pattern Matching).


Top
 Profile  
 PostPosted: Mon May 13, 2013 2:34 pm   

Joined: Fri May 10, 2013 12:23 pm
Posts: 5
Thanks that does help,

i do have one request.

can you help me by Highlighting which "/"s are part of

{parameter/pattern/string} and which are pattern matching?

cause currently i see 3 "/" and only two would be part of the {parameter/pattern/string}

${line / *\ / *! / * *! } the red one i assume is the first one.

so should i read this as ${line/ *\ / *!/**! }

or
${line / *\/*! / **! }.

Finally even with a web search i have no idea what a '!' After the symbols mean (before the symbols i would assume it is 'not' or 'negate')

thanks in advance


Top
 Profile  
 PostPosted: Mon May 13, 2013 4:56 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 548
the protected one (\/) is part of the pattern, it's protected so it can't be taken for a separator.
I think exclamation marks are simply litteral exclamation marks.


Top
 Profile  
 PostPosted: Wed May 15, 2013 2:44 pm   

Joined: Fri May 10, 2013 12:23 pm
Posts: 5
Thank you I did figure this out, Watael you were most helpful.

so the end result the line found this --- * /*! --- and replace it with this --- * *! ---

(ignore the dashes)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP