On Tue, Feb 09, 2010 at 09:18:47PM -0800, DennisW wrote:
> * means zero or more characters. It found zero and stopped. You could
> do:
> 
> [[ '/home/' =~ /([^/]*) ]]; echo ${BASH_REMATCH[1]}

Oh, is he trying to get the first non-null component of a /-delimited
pathname?  I can never tell any more....

IFS=/ read -a tmp <<< '/home/'; echo "${tmp[1]}"

Using regular expressions to split a string into fields is so unnatural
to me.  ${tmp[1]} is the second element of the array.  If you need to
search through it for the first non-null element, you can write a loop
for that.


Reply via email to