Hi,
imagine my shell script gets called with a random amount of arguments.
Those arguments must be passed to another program:
So far so good. But - I need to modify the parameters before they are passed.
I need to remove a specific string from one of the parameters. Which parameter the string contains is not known. The parameters may contain spaces and it is important that an argument/parameter which contains a space is forwarded as a single parameter to the binary.
What I tried:
But this is not working, assume the script gets called like this:
$3 does not contain "1 2 3", instead it contains "1
Any ideas how to solve this problem properly?
imagine my shell script gets called with a random amount of arguments.
Those arguments must be passed to another program:
Code:
/usr/local/bin/binary "$@"
So far so good. But - I need to modify the parameters before they are passed.
I need to remove a specific string from one of the parameters. Which parameter the string contains is not known. The parameters may contain spaces and it is important that an argument/parameter which contains a space is forwarded as a single parameter to the binary.
What I tried:
Code:
#!/bin/sh
while [ $# -gt 0 ] ; do
if echo "$1" |grep -q ' ' ; then
OPT=$OPT' "'$1'"'
else
OPT=$OPT' '$1
fi
echo $1
shift 1
done
OPT=$(echo "$OPT" | sed 's|:vrc_maxrate=[0-9]*||g')
OPT=$(echo "$OPT" | sed 's|:vrc_buf_size=[0-9]*||g')
set -- $OPT
echo $3
/usr/local/bin/mencoder.orig "$@"
But this is not working, assume the script gets called like this:
Code:
/usr/local/bin/mencoder -ss 0 "1 2 3" 4 5
$3 does not contain "1 2 3", instead it contains "1
Code:
$ /usr/local/bin/mencoder -ss 0 "1 2 3" 4 5
-ss
0
1 2 3
4
5
"1