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?
1 Answer
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" "$@"
2 Comments
Charles Duffy
...already have two linked duplicates that are precisely on-point, no?
chepner
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.
shdoesn't have arrays. Why is this tagged sh?"$@"), instead of actually expanding an array onto it.