we are on Debian 11. I'd like to use grep and awk to retrieve information from the content of a single file, like the following:
file: /home/user/directory/otherdirectory/data.txt
file content:
$db['data_config']['hostname'] = 'localhost';
$db['data_config']['username'] = 'userbitch';
$db['data_config']['password'] = 'HD3hdkskdks343kdksk43';
$db['data_config']['database'] = 'userbitch_database';
When I use shell directly, this command give out the exact result: userbitch
$ CONF="/home/user/directory/otherdirectory/data.txt"
$ grep 'data_config' $CONF | grep 'username' | awk -F\' '{ print $6 }'
But when I apply this command in a shell script (exec.sh), it return errors:
./exec.sh: line n#: grep: command not found
./exec.sh: line n#: grep: command not found
./exec.sh: line n#: awk: command not found
I've try some combination of debug, like /$6 suspecting the murder is the dollar sign of awk variable. How can I get the result of the "data_config" strings encapsulated in the single quote without using awk? Exists another combination of regex or print variable that doesn't trow out errors?
Very thanks for your attention.