Looking for a way to split following argument passed to a shell script in a single line. Input
my_script.sh "memory":"8"
I am trying to find a way to allocate maximum memory to run java program. If value is 8, I will start java with 8GB of memory(-Xmx8G) and if memory is not passed, java will be run without Xmx option.
Note: Earlier I tried thisbut looks like ':' need a special treatment. Also I need to figure out within a line.
#!/bin/bash
echo "First arg: $1"
IFS=':'
read -ra arr <<< $1
for val in "${arr[@]}";
do
printf "name = $val\n"
done
printf "name = ${arr[1]}\n"
Result
% ./myscript.sh "memory":"8"
First arg: memory:8
name = memory 8
name =