mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-25 23:47:53 +00:00
env_parallel.bash: parset: Error handling if destination variable set wrongly.
This commit is contained in:
parent
144164d516
commit
21d3b7d9be
|
@ -203,6 +203,22 @@ parset() {
|
||||||
|
|
||||||
_parset_name="$1"
|
_parset_name="$1"
|
||||||
shift
|
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
|
if echo "$_parset_name" | grep -E ',| ' >/dev/null ; then
|
||||||
# $1 contains , or space
|
# $1 contains , or space
|
||||||
# Split on , or space to get the names
|
# Split on , or space to get the names
|
||||||
|
|
|
@ -20,7 +20,7 @@ B<parallel> into shell variables.
|
||||||
The B<parset> function is defined as part of B<env_parallel>.
|
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
|
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,
|
If I<variablename> contains multiple names separated by ',' or space,
|
||||||
the names will be the destination variables.
|
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[0]}"
|
||||||
echo "${res[9]}"
|
echo "${res[9]}"
|
||||||
|
|
||||||
|
or Bash process substitution:
|
||||||
|
|
||||||
|
parset res echo :::: <(seq 100)
|
||||||
|
echo "${res[0]}"
|
||||||
|
echo "${res[99]}"
|
||||||
|
|
||||||
=head3 Installation
|
=head3 Installation
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue