> PY=`pkg rquery -r FreeBSD "%dn" lang/python | head -n 1 | sed "s/python//"` You can even replace head with a sed command if you need to save some characters on the line: PY=`pkg rquery -r FreeBSD "%dn" lang/python | sed "s/python//;1q"` >