Consider the following in a bash script:
STOP_SEARCH_STR="'""for $TASKNAME""'"
echo $STOP_SEARCH_STR # prints 'for Our Special Task_4'
echo "$STOP_SEARCH_STR" # prints 'for Our Special Task_4'
echo "grep -F "$STOP_SEARCH_STR" "$TEMP"/draft" # prints grep -F 'for Our Special Task_4' /tmp/draft
echo "$(grep -F "$STOP_SEARCH_STR" "$TEMP"/draft)" # prints nothing!
echo $("grep -F "$STOP_SEARCH_STR" "$TEMP"/draft") # prints nothing!
And the following content in the $TEMP/draft text file:
2019-11-21 08:13:58,825 Task started: 'Our Special Task_4' of type 'Our - Special Task'
2019-11-21 08:14:10,509 Task ended: 'Success' for Our Special Task_4 -- Elapsed time: 11.0 seconds
If I manually type the command grep -F 'for Our Special Task_4' /tmp/draft
, I receive the second line in the draft text file:
2019-11-21 08:14:10,509 Task ended: 'Success' for Our Special Task_4 -- Elapsed time: 11.0 seconds
But the the last 2 commands above (inside a bash script) print nothing!
Any idea why?
STOP_SEARCH_STR
. They are being treated as part of the string to search for. – Gordon Davisson Nov 23 '19 at 18:36for Our Special Task_4
. – datsb Nov 23 '19 at 18:50grep -F
". – Kusalananda Nov 23 '19 at 19:20