Question: I'm trying to better organise a bash script as part of a re-write/re-organisation and am wondering what "best practice" is in the following situation:

```
ymd=`echo "${NOEXT}" | egrep -o -m 1 "\-20[0-9]{2}\-[0-9]{2}\-[0-9]{2}\-"`

```

or

```
ymd=`egrep -o -m 1 "\-20[0-9]{2}\-[0-9]{2}\-[0-9]{2}\-" <<< ${NOEXT}` 

```

I believe the first version, due to the pipe, creates a subshell. Does the second version with the here string? I'm figuring it doesn't, but want to validate my assumptions.

Answer: 
The latter doesn't which you can (roughly) verify by looking (on an idle system) at the increase of the PIDs - when running the former, it will increase by 2, when running the latter, it will only increase by 1.

But, it's a [Bashism](http://mywiki.wooledge.org/Bashism), and maybe should be replaced with a here document:

```
ymd=`egrep -o -m 1 "\-20[0-9]{2}\-[0-9]{2}\-[0-9]{2}\-" <<EOF
${NOEXT}
EOF`

```
If you can use `bash` and don't require POSIX compatibility, you can do the regular expression match without using the external call to `egrep`.

```
[[ $NOEXT =~ -20[0-9]{2}-[0-9]{2}-[0-9]{2}- ]]
ymd=${BASH_REMATCH[0]}

```