env_parallel.bash: parset: Error handling if destination variable set wrongly.

This commit is contained in:
Ole Tange 2017-06-29 04:21:44 +02:00
parent 144164d516
commit 21d3b7d9be
2 changed files with 23 additions and 2 deletions

View file

@ -203,6 +203,22 @@ parset() {
_parset_name="$1"
shift
if [ "$_parset_name" == "" ] ; then
echo parset: Error: No destination variable given. >&2
echo parset: Error: Try: >&2
echo parset: Error: ' ' parset myvar echo ::: foo >&2
return 255
fi
echo "$_parset_name" |
perl -ne 'chomp;for (split /[, ]/) {
if(not /^[a-zA-Z_][a-zA-Z_0-9]*$/) {
print STDERR "parset: Error: $_ is an invalid variable name.\n";
print STDERR "parset: Error: Variable names must be letter followed by letters or digits.\n";
$exitval = 255;
}
}
exit $exitval;
' || return 255
if echo "$_parset_name" | grep -E ',| ' >/dev/null ; then
# $1 contains , or space
# Split on , or space to get the names

View file

@ -20,7 +20,7 @@ B<parallel> into shell variables.
The B<parset> function is defined as part of B<env_parallel>.
If I<variablename> is a single variable name, this will be treated as
the destination variable and made to an array.
the destination variable and made into an array.
If I<variablename> contains multiple names separated by ',' or space,
the names will be the destination variables.
@ -71,6 +71,11 @@ You cannot pipe into B<parset>, but must use a tempfile:
echo "${res[0]}"
echo "${res[9]}"
or Bash process substitution:
parset res echo :::: <(seq 100)
echo "${res[0]}"
echo "${res[99]}"
=head3 Installation