mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-28 01:51:33 +00:00
"env grep" - add options to grep in name, value, or both.
Add options to "env grep" command: -n : search only the envrironment variable names -v : search only their values -b : search both names and values (= default) An option "--" will stop parsing options, so to print variables that contain the striing "- " please use: env grep -- "- " Or to print all environment varioables which have a '-' in their name, use: env grep -n -- - Signed-off-by: Wolfgang Denk <wd@denx.de>
This commit is contained in:
parent
5a31ea04c9
commit
d87244d5af
1 changed files with 33 additions and 5 deletions
|
@ -165,13 +165,39 @@ static int do_env_grep(cmd_tbl_t *cmdtp, int flag,
|
||||||
int argc, char * const argv[])
|
int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
char *res = NULL;
|
char *res = NULL;
|
||||||
int len;
|
int len, grep_flags;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
return CMD_RET_USAGE;
|
return CMD_RET_USAGE;
|
||||||
|
|
||||||
|
grep_flags = H_MATCH_BOTH;
|
||||||
|
|
||||||
|
while (argc > 1 && **(argv + 1) == '-') {
|
||||||
|
char *arg = *++argv;
|
||||||
|
|
||||||
|
--argc;
|
||||||
|
while (*++arg) {
|
||||||
|
switch (*arg) {
|
||||||
|
case 'n': /* grep for name */
|
||||||
|
grep_flags = H_MATCH_KEY;
|
||||||
|
break;
|
||||||
|
case 'v': /* grep for value */
|
||||||
|
grep_flags = H_MATCH_DATA;
|
||||||
|
break;
|
||||||
|
case 'b': /* grep for both */
|
||||||
|
grep_flags = H_MATCH_BOTH;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
goto DONE;
|
||||||
|
default:
|
||||||
|
return CMD_RET_USAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DONE:
|
||||||
len = hexport_r(&env_htab, '\n',
|
len = hexport_r(&env_htab, '\n',
|
||||||
flag | H_MATCH_BOTH | H_MATCH_SUBSTR,
|
flag | grep_flags | H_MATCH_SUBSTR,
|
||||||
&res, 0, argc, argv);
|
&res, 0, argc, argv);
|
||||||
|
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
|
@ -1127,7 +1153,7 @@ static char env_help_text[] =
|
||||||
"env flags - print variables that have non-default flags\n"
|
"env flags - print variables that have non-default flags\n"
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_CMD_GREPENV)
|
#if defined(CONFIG_CMD_GREPENV)
|
||||||
"env grep string [...] - search environment\n"
|
"env grep [-n | -v | -b] string [...] - search environment\n"
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_CMD_IMPORTENV)
|
#if defined(CONFIG_CMD_IMPORTENV)
|
||||||
"env import [-d] [-t | -b | -c] addr [size] - import environment\n"
|
"env import [-d] [-t | -b | -c] addr [size] - import environment\n"
|
||||||
|
@ -1174,8 +1200,10 @@ U_BOOT_CMD_COMPLETE(
|
||||||
U_BOOT_CMD_COMPLETE(
|
U_BOOT_CMD_COMPLETE(
|
||||||
grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
|
grepenv, CONFIG_SYS_MAXARGS, 0, do_env_grep,
|
||||||
"search environment variables",
|
"search environment variables",
|
||||||
"string ...\n"
|
"[-n | -v | -b] string ...\n"
|
||||||
" - list environment name=value pairs matching 'string'",
|
" - list environment name=value pairs matching 'string'\n"
|
||||||
|
" \"-n\": search variable names; \"-v\": search values;\n"
|
||||||
|
" \"-b\": search both names and values (default)",
|
||||||
var_complete
|
var_complete
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue