Error running script

Hi,

I have the the below script

more runcda.sh
if [ $(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' $1_dr) ]; then
echo "ParallelGCThreads Found with Value"
else
echo "ParallelGCThreads Not Found - Add !!"
fi

$ ./runcda.sh output.log
./runcda.sh: test: argument expected
ParallelGCThreads Not Found - Add !!

Why am i getting the bold error and how can i get rid of it ?

Try:

if [ "$(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' "$1_dr")" ]; then

Otherwise there will be an error is there when the result is empty.

1 Like

Add quotes:

if [ "$(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' $1_dr)" ]; then

Note that the way you have this written, your script will say ParallelGCThreads Found with Value even if there are no digits following the equal sign. If you want to require at least one digit to be present, try:

if [ "$(sed -n 's/.*\(ParallelGCThreads=[0-9][0-9]*\).*/\1/p' $1_dr)" ]; then
1 Like