I am trying to use /bin/sh -c
to execute a .sh script with a date parameter. The -c option is not optional as it's what the framework my team has uses. I can't get the date epoch parameter to pass to my script properly. The following is an example demonstrating how calling a file causes the parameters not to work whereas passing a command directly works fine. The middle command (without the -c) is the expected output with each number repeating.
root:xxxxx@xxxx:/opt/xxxxxx/software_versions> /bin/sh -c /opt/xxxxxx/software_versions/test2.sh 1 2 3 4
1
2
3
4
root:xxxxx@xxxx:/opt/xxxxxx/software_versions> /bin/sh /opt/xxxxxx/software_versions/test2.sh 1 2 3 4
11
22
33
44
root:xxxxx@xxxxx:/opt/xxxxxx/software_versions> /bin/sh -c 'echo $1 echo $2' a b c d
b echo c
Script contents:
echo 1$1
echo 2$2
echo 3$3
echo 4$4
/bin/sh -c
with some arguments and you need access to the positional parameters in that shell. Right, so you don't control the-c
part. What do you control? You'll probably have to find a hack to somehow make it introduce the necessary quoting or else add parameters to the/opt/xxxxxx/software_versions/test2.sh
script or something, but what solution is possible depends on what part of the command template is under your control and what part is fixed. – Celada May 26 '16 at 21:30