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?

Matt Curry
  • 99
  • 7
  • `sh` doesn't _have_ arrays. Why is this tagged sh? – Charles Duffy Sep 03 '21 at 17:19
  • BTW, to really copy content in an array, see https://stackoverflow.com/a/1063367/14122. The linked duplicates are for passing through the argument list (with `"$@"`), instead of actually expanding an array onto it. – Charles Duffy Sep 03 '21 at 17:22

1 Answers1

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" "$@"
chepner
  • 497,756
  • 71
  • 530
  • 681
  • ...already have two linked duplicates that are precisely on-point, no? – Charles Duffy Sep 03 '21 at 17:22
  • 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. – chepner Sep 03 '21 at 17:24