[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] pass command to script
From: |
Jesse Hathaway |
Subject: |
Re: [Help-bash] pass command to script |
Date: |
Thu, 25 Apr 2019 12:59:41 -0500 |
On Thu, Apr 25, 2019 at 10:49 AM Christof Warlich <address@hidden> wrote:
> Is there any chance to achive something similar with a script?
Chris, does this achieve your goal?:
> cat test.sh
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
declare -a envs
for arg in "address@hidden"; do
if [[ $arg == '--' ]]; then
shift
break
fi
envs+=("${arg}")
shift
done
(
for env in "address@hidden"; do
declare -x "${env}"
done
"$@"
)
> ./test.sh 'foo=butter & bubbles' 'bar=balloon & bananas' -- bash -c 'printenv
> foo bar'
butter & bubbles
balloon & bananas