Is it possible to modify the arguments passed to a bash program ? and then pass them to a Java program ?
I know we can access all the arguments passed to a bash program by "$@"
and I can pass them to Java program like java com.myserver.Program "$@"
. But is it possible to modify value of certain arguments inside "$@"
and then call the above java program with "$@"
?
I also know you can use "$@[1]"
to access the value of arguments but how can we iterate over them and change the value at the proper position ? I also know this :
for arg
do
....
done
But inside the do loop how can the value of argument be modified and then java program be called ?
Iterate through every item in the positional parameters, then add them to another array, modifying it if needed while you do.
ARGS=()
for A in "$@"; do
# Modify A then add it to args.
# A=${A//something/something} ## Just an example.
ARGS+=("$A")
done
# Then call java:
java com.myserver.Program "${ARGS[@]}"
And since you're processing positional parameters, it would be simpler to use this form of for
:
for A; do
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.