find in bash script returns "missing argument to `-exec'" while cmd runs fine
Hi folks,
i wrote a little shell script involving find. I use variables to construct the final find command. While running the echoed find command on cmd line everything works fine but inside the bash script find returns "/usr/bin/find: missing argument to `-exec'". Anyone can help me out on this? Code:
#!/bin/bash |
I haven't tested but you may be finding files with spaces in the path, try adding some quotes.
|
Code:
FIND_EXC_TAR="-exec ls \{\} \;" Code:
FIND_EXC_TAR="-exec ls {} ;" |
More often than not you will find it better to place commands into a function and call it then using variables which may perform unexpectedly.
|
@kdp: So where should I add the quotes?
@NevemTeve: That way it works, thanks a lot. I guess its the way bash handles variables. You have an idea where I can read up on this in more depth? As man find says that one has to escape {} and ;... @grail: I'll consider this. |
Quote:
From Looping Constructs (about ;): "Note that wherever a ‘;’ appears in the description of a command's syntax, it may be replaced with one or more newlines ". As for {}, this meaning may be removed by escaping or quoting but using both passes \; to find. |
Read here for why you shouldn't store command syntax in a variable:
http://mywiki.wooledge.org/BashFAQ/050 Do as grail suggested and set it up as a function. Or if you absolutely insist on using variables, at least put it an array and store each option in a separate position. |
Thanks to be both of you catkin and David. I already skimed over the links but are about to understand them fully.
So catkin if I understand it right you say that. Code:
" \{\} " I'll just have myself another look at the bash man page as well as the BASH Scripting Tutorial to get on better ground. I think I have to dig some more on how bash interprets files in relation to command lines. |
From the GNU Bash Reference on Double Quotes: "The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified".
|
All right. Thanks catkin.
|
If the problem is now solved you can mark the thread SOLVED via the Thread Tools menu.
EDIT: actually you can mark it SOLVED whether or not it is actually solved ... but you know what I am expressing badly. |
thanks for the reminder. Jup the problem itself is solved.
|
All times are GMT -5. The time now is 05:34 PM. |