find: problems escaping printf-command string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find: problems escaping printf-command string
# 1  
Old 12-04-2005
find: problems escaping printf-command string

Hi Folks!

Can you help me with this find -printf command. I seem to be unable to execute the printf-command from my shell script. I'm confused: Smilie

My shell script snippet looks like this:
Code:
#!/bin/sh
..
COMMAND="find ./* -printf '%p %m %s %u %g \n'"
echo "Command: ${COMMAND}"
${COMMAND} > ${ARCHIVE_DIR}/${CURRENT_FILE}

With or without the single quotes enclosing the %p, etc, I get this error message:
Code:
Command: find ./* -printf '%p %m %s %u %g \n'
find: paths must precede expression

At the command line (bash), the command works. Further-more it only works for me with the single quotes enclosing the printf-command string.

Look forward to your replies
Grahamb

Using Fedora2.54 with bash; and #!/bin/sh for shell execution
# 2  
Old 12-04-2005
Question That dammed substitution!

Hi You Guys!

I'm sure most of you have an answer to this one. Smilie I'm trying to do a work around on the problem above, but get held up elsewhere!!!!! Smilie So can't avoid this problem.

Here's my next stopper:
Code:
COMMAND="ls -la --full-time `find ./* -type f` "
${COMMAND} | awk '''{ print '$NF' '$0' }''' >> ${ARCHIVE_DIR}/${TMP_FILE}

The log file shows this error:
Code:
+ awk '{ print  /usr/share/scripts/security_check.sh }'

I'm half way there. I have the '{ }' parts carried to the command line. BUT the "$NF" is substituted to be blank and "$0" is substitued as the calling program!!

When I put \$NF inside the awk-brackets the "\" gets sent to the command line, eg:
Code:
+ awk '{ print  \$NF \$0 }'

Close but not close enough!

Can u help? Any ideas? Any links to help me?

regards
GrahamB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with bash escaping while using screen command

Hello, everyone. I'm currently trying to write a command system for a Minecraft server using screen. Here are the scripts I'm currently using. 0.sh #!/bin/bash screen -S Test114 -dm java -Xmx4G -jar server.jar nogui 1.sh #!/bin/bash args="$@" args2="${args@Q}" #args3=`printf '%q\n'... (2 Replies)
Discussion started by: Develon
2 Replies

2. Shell Programming and Scripting

Printf padded string

Is possible to print padded string in printf? Example echo 1 | awk '{printf("%03d\n", $1)}' 001I want S1 S11 S2 S21to be padded as: S01 S11 S02 S21Thanks! (26 Replies)
Discussion started by: yifangt
26 Replies

3. Shell Programming and Scripting

Problems with awk printf, formatted output

Hi, i have a script, which is incomplete, am on my way developing it. Input 1,12,2012,IF_TB001 2,12,2012,3K3 3,Z56,00000,25,229,K900,00, ,3G3, ,USD, ,0000000000,000, , , , 550000000 3,Z56,00000,53,411,W225,00,000, , ,USD,OM170,0000000000,000, , , , -550000000 4,Z56,COUNT, 4,SUM LOC,... (19 Replies)
Discussion started by: selvankj
19 Replies

4. Shell Programming and Scripting

problems with ksh array and find command

set -A allfiles `find $usrhtml -type f` i am trying to populate this array with the find command. It works fine when find is looking through a single directory but when i add a new subdirectory the files in the subdirectory get duplicated. Can anyone help me and fix this so each files in... (1 Reply)
Discussion started by: bjhum33
1 Replies

5. Shell Programming and Scripting

escaping metacharacters in paths for a shell command

I have a file which contains a list of paths separated by a new line character. e.g /some/path/to/a/file.png /some/path to/another/file.jpeg /some path/to yet/another/file Notice that these paths may contain metacharacters, the spaces for example are also not escaped. If I wanted... (5 Replies)
Discussion started by: cue
5 Replies

6. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

7. Shell Programming and Scripting

Help formatting a string. Something like printf?

Hi I'm having a problem with converting a file: ID X 1 7 1 8 1 3 2 5 2 7 2 2 To something like this: ID X1 X2 X3 1 7 8 3 2 5 7 2 I've tried the following loop: for i in `cat tst.csv| awk -F "," '{print $1}'| uniq`;do grep -h $i... (4 Replies)
Discussion started by: flotsam
4 Replies

8. UNIX for Advanced & Expert Users

Help please...output problems with printf.

#include <stdio.h> #include <math.h> // this function calculates the volume of a Cylinder int main(void) { int r; // radius int h; // height double M_PI; // pi int pOne = pow (r, 2); // get user input of radius and height printf ("Enter your... (3 Replies)
Discussion started by: pwanda
3 Replies

9. UNIX for Dummies Questions & Answers

Problems with find command

Folks, I have been searching a dir for specfic files that have been accessed within a certain timeframe. The issue that I am having is that it picks up the .snapshot dir as well. I am using the following: find /probecards/ -name "S25E3N*" -mtime -1 -type f Is this correct or how do I... (4 Replies)
Discussion started by: lodey
4 Replies

10. UNIX for Dummies Questions & Answers

ctrl-c: not escaping command

using ksh on HP 11.11. I'm new to HP, so maybe it's something I need to turn on in HP, but I figured it's probably in ksh. If I run "grep aaa" (or any command) Whenever I try to Ctrl-C it does not work. I'm not saying it did work before, as I'm new to the environment. Do I need to set a... (3 Replies)
Discussion started by: dangral
3 Replies
Login or Register to Ask a Question