0

Basically, I wrote a bash script to act as a wrapper script for other scripts. The idea is to pass the name of the script you want to run with its arguments, then my script sets some global vars and makes sure you are allowed to use the given inputs, then calls the script with the given args. So how would I invoke the script given as an argument with the given parameters in bash code?

2
  • sh doesn't have arrays. Why is this tagged sh? Commented Sep 3, 2021 at 17:19
  • BTW, to really copy content in an array, see stackoverflow.com/a/1063367/14122. The linked duplicates are for passing through the argument list (with "$@"), instead of actually expanding an array onto it. Commented Sep 3, 2021 at 17:22

1 Answer 1

1

The arguments you receive are in "$@"; you can use that to pass them on.

#!/bin/bash

script=$1
shift

for x in "$@"; do
    # validate remaining arguments
done

"$script" "$@"
Sign up to request clarification or add additional context in comments.

2 Comments

...already have two linked duplicates that are precisely on-point, no?
Subtle difference (IMO, anyway): one of the arguments is the script to run itself, rather than an an argument to pass on to a hard-coded command.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.