Sample Header Ad - 728x90

grep return "No such file or directory" after command substitution

3 votes
1 answer
274 views
I'm trying to use grep in a bash script and assign the result to a variable:
-bash
RESUlT=$(grep -R -I --exclude-dir=addons "^[^#]*print(" )
But it returns bash: Map/Places/place.gd:: No such file or directory I tested it in my terminal and
-bash
grep -R -I --exclude-dir=addons "^[^#]*print("
returns what I expect, but
-bash
$(grep -R -I --exclude-dir=addons "^[^#]*print(" )
returns the error. I have no idea why that happens. My whole Script:
-bash
#!/bin/bash

CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m' # No Color

RESUlT=$(grep -R -I --exclude-dir=addons "^[^#]*print(" )
echo "${RESULT}"
echo -e "${CYAN}I ${RED}love${NC} Stack Overflow"
What bash does:
-bash
**bash -o xtrace .check_code.sh** 
+ CYAN='\033[0;36m'
+ RED='\033[0;31m'
+ NC='\033[0m'
++ grep -R -I --exclude-dir=addons '^[^#]*print('
+ RESUlT='Map/Places/place.gd:	print("enter")'
+ echo ''

+ echo -e '\033[0;36mI \033[0;31mlove\033[0m Stack Overflow'
I love Stack Overflow
One weird thing in the Terminal:
-bash
whereis grep
returns
-bash
grep: /usr/bin/grep /usr/share/man/man1/grep.1.gz /usr/share/info/grep.info.gz
**But:**
-bash 
$(whereis /usr/bin/grep)
returns
-bash
Command 'grep:' not found, did you mean:
  command 'grep' from deb grep (3.11-2)
Try: sudo apt install
Asked by T.S (33 rep)
Jun 27, 2024, 10:12 AM
Last activity: Nov 24, 2024, 02:17 PM