You are not logged in.
# strip the rows number, we just want columns
STAT_COL=${STAT_COL##* }
STAT_COL##* uses REGULAR EXPRESSIONS right.
Need an answer as Yes or No. I would dig out the rest of it myself
Thanx in advance !!
Last edited by Onwards (2008-07-29 17:19:26)
Offline
No. Considering you want to research this yourself: http://tldp.org/LDP/abs/html/
The terminology you want is "globbing"
Offline
THANKYOU for the quick reply and the link, of course !!
Offline
OK a bit of explanation for the late-comers
My question was about a line in /etc/rc.d/functions script. Here are the dubious lines...
STAT_COL=$(/bin/stty size)
# strip the rows number, we just want columns
STAT_COL=${STAT_COL##* }
As the commented out line says, we just want number of columns. But the output of stty size is like "40 143" i.e. "40 rows AND 143 cols". So our job is to strip the no. of rows from this string i.e. we want to reduce it to "143".
STAT_COL is a shell variable and we can use it as an array. It would be treated as an array containing a single element. To use it as an array, just embed it inside ${variable}.
Now we 've got to do Substring Removal on it, longest match from the front of the string in fact. "##* " would match anything followed by a space to be removed from the string. Th result is stord back into STAT_COL. Thus we are left with just the no. of columns.
For further details have a look at http://tldp.org/LDP/abs/html/arrays.html.
Last edited by Onwards (2008-07-29 19:11:11)
Offline
This explanation is mostly accurate. However this is not correct:
STAT_COL is a shell variable and we can use it as an array. It would be treated as an array containing a single element. To use it as an array, just embed it inside ${variable}.
${STAT_COL} is not an array. It's an ordinary simple zero-dimensional variable. The only role that the {}s play is to let the shell's parser interpret what you're writing. If you just wrote $STAT_COL*<space>, the parser would see that as $STAT_COL followed by * followed by <space>. Instead you want the shell to see a single token: not $STAT_COL but rather <the result of chopping the glob pattern "* " off of the start of $STAT_COL>. That's what ${STAT_COL#* } gives you.
To interpret STAT_COL as an array, you'd instead have to write this:
STAT_ARRAY=( $STAT_COL ) # it's important here not to put ""s around $STAT_COL
STAT_ROWS=${STAT_ARRAY[0]}
STAT_COLS=${STAT_ARRAY[1]}
---which the authors of /etc/rc.d/functions might also reasonably have done.
Offline