-2

we have the following file:

more test.txt

export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g"
export KAFKA_JVM_PERFORMANCE_OPTS="-XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M -XX:MinMetaspaceFreeRatio=50 -XX
:MaxMetaspaceFreeRatio=80"

how to verify the lines:

export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g"

and

export KAFKA_JVM_PERFORMANCE_OPTS="-XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M -XX:MinMetaspaceFreeRatio=50 -XX
    :MaxMetaspaceFreeRatio=80"

are exists in the file - test.txt

of course , we can do

grep -q 'export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g"' test.txt 
[[ $? -eq 0 ]] && echo "line in file"


grep -q 'export KAFKA_HEAP_OPTS="export KAFKA_JVM_PERFORMANCE_OPTS="-XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M -XX:MinMetaspaceFreeRatio=50 -XX
        :MaxMetaspaceFreeRatio=80"' test.txt 
[[ $? -eq 0 ]] && echo "line in file"

but this approach is very clumsy

  • Why is it clumsy to use a tool that’s built to search for text to search for text? You’d just have to escape any regex characters, but since you already know what text you’re searching for, that’s easy. – Jeff Schaller Jun 10 '18 at 13:52
  • If you're trying to find the exact line, use grep options -F and -x – glenn jackman Jun 10 '18 at 13:55
-1
#! /bin/bash

env - bash -c '. test.txt; [ -n "$KAFKA_HEAP_OPTS" ] && [ -n "$KAFKA_JVM_PERFORMANCE_OPTS" ]'
if [ $? -eq 0 ]; then
     echo 'OK'
else
    echo 'ERROR'
fi
  • this are only the variables , what about all values that variables are represented ? – yael Jun 10 '18 at 11:33
  • KAFKA_HEAP_OPTS_ should be KAFKA_HEAP_OPTS – yael Jun 10 '18 at 11:33
  • 1
    @yael I doubt that you will get the answer you are looking for without a reasonable definition of "clumsy"... – Hauke Laging Jun 10 '18 at 11:38
  • since I not get other idea / answers I prefer to delete my question , do you want also to delete ? – yael Jun 10 '18 at 11:55
  • @yael That is a strange reaction after not even an hour and after not improving your question but if you feel that is the right thing to do then just delete your question... – Hauke Laging Jun 10 '18 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.