Reputation:
It is about following setup: Linux machine, bash, adb, embedded Linux target system with Busybox. For target system following applies:
adb shell echo $SHELL
/bin/sh
adb shell echo $0
/bin/sh
The problem is my find command in some script does not find anything (it has been proved by other means that items being looked for in fact do exist on target). My command:
adb -s $AdbID shell find / -type f \( -name "'"*audio*"'" -or -name "'"*alsa*"'" \) \
\( -path "'"/usr/lib/*"'" -or -path "'"/usr/bin/*"'" -or -path "'"/etc/*"'" \)
If to debug with echo echo gets following string as input arguments:
$ adb -s $AdbID shell echo find / -type f \( -name "'"*audio*"'" -or -name "'"*alsa*"'" \) \
\( -path "'"/usr/lib/*"'" -or -path "'"/usr/bin/*"'" -or -path "'"/etc/*"'" \)
find / -type f ( -name '*audio*' -or -name '*alsa*' ) \
( -path '/usr/lib/*' -or -path '/usr/bin/*' -or -path '/etc/*' )
Note: above transcript uses escaped newlines so you dont need to scroll much here, however those are not used in original command.
I guess same will apply to find if to remove echo from command string. For me it looks like Busybox was not doing the quotes removal as myself used to have in Bash, after expansions of all other kinds. Ash as it seems to be Busybox shell, in its manual no word reg. quotes removal was found, so no idea how ash works in this regards.
#If to replace Linux host with Windows desktop machine + dos command line, remaining elements as in case above* the command works fine. One can figure out difference at following point:
*) actually also other target system, however on this side no intentional changes so both setups should be identical regarding target system.
If to debug with echo echo gets following string:
c:\adb_shell>adb -s 2233445 shell echo find / -type f \
\( -name "'"*audio*"'" -or -name "'"*alsa*"'" \) \
\( -path "'"/usr/lib/*"'" -or -path "'"/usr/bin/*"'" -or -path "'"/etc/*"'" \)
find / -type f ( -name *audio* -or -name *alsa* ) \
( -path /usr/lib/* -or -path /usr/bin/* -or -path /etc/* )
Here the command gets from shell the string of input arguments with quotes removed.
I realize just the minute as myself writes this Q that command grouping will also not work as expected (busybox shell will consume paranthesis so 'find' won't receive them), let's address this question in other scope. Possibly command has more errors of this kind.
I believe the lack of quotes removal in case of two Linux shells in a chain is also real problem for my command string. What are possible reasons, solutions?
Upvotes: 0
Views: 488
Reputation: 72609
Note that in
"'"*audio*"'"
the asterisks are not escaped from the shell. The shell will happily glob them, should a file matching *audio*
be in the current working directory. If the '
are really part of the filenames, you want to use "'*audio*'"
instead. Then find
will seach for files named '*audio*'
(where find
, not the shell, does the globbing for *
).
If you simply want to find files matching *audio*
(audio anywhere in the name), then use -name "*audio*"
etc.
It would help if you told us exactly what the file names you want to find are.
Upvotes: 1