bash - using grep to check file content in hidden directory -
bash - using grep to check file content in hidden directory -
i have next function in shell script meant handle basic grep checks server setting in ~/.m2/settings.xml:
settings_file="~/.m2/settings.xml" settings_server_id="<id>ossrh</id>" check_settings () { echo grep "$1" "$settings_file" if grep -q "$1" "$settings_file"; echo "server set up...\n"; else echo "deploy failed:\n\t$1 not found in ${settings_file}! fail "fail :("; fi homecoming 0 } check_settings $settings_server_id
unfortunately, results in next message:
grep <id>ossrh</id> ~/.m2/settings.xml grep: ~/.m2/settings.xml: no such file or directory deploy failed: <id>ossrh</id> not found in ~/.m2/settings.xml! fail :(
meanwhile, using grep "<id>ossrh</id>" ~/.m2/settings.xml
in bash returns <id>ossrh</id>
, expected.
i'm wondering if issue of visibility- whether grep can see things in hidden directories (unlikely, considering this question) or whether issue argument i'm passing grep (likely, considering how new shell scripting)
the ~/
prefix not expanded home directory when variable value in quotes. alter first line to:
settings_file=~/.m2/settings.xml
the clue error message includes ~
prefix. if prefix had been expanded, error message have contained absolute pathname directory.
bash shell maven grep sh
Comments
Post a Comment