Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C shell syntax problem 1

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
US
Hi,

Dies anyone know the correct syntax for this command?

set File='find . -name "*" -mtime +13+14 -exec {}\;'

I want to assign the Variable File to find . -name "*" -mtime +13+14 -exec {}\;, however am having syntax problems. I am using csh.

Thanks,
 
Thanks,

But I want to run this command, and assign it's output to a variable, this is where I am having difficulties.....
 
that EXACTLY what this 'construct' does!

I'd suggest reading csh's man pages regarding either 'active functions' and/or 'backquotes'

vlad
 
Hi,
I think you are confusing the

' single quote '

with the

` back quote `

Again you have to remember that you can only SET 1 word to a variable unless you put it in Quotes or sorround it by (). Most likely this Find will find multiple files and CSH will croak.

therefore you need to use them both here.

set File='`find . -name "*" -mtime +13+14 -exec {}\;`'


However looking at your command.....

The -exec scares me as this will execute some command for every file found and concatentate the reultant strings into one HUGE string in FILE.

Maybe you meant -print instead of -exec? -exec requires a command.


for example

set File='`find . -name "*" -mtime +13+14 -exec ls -l {}\;`'

would exec the ls -l command for every file the FIND finds and then return the output to you a One Gigantic string.

In that case you are better off separarting the exec from the find.

foreach file ( ` find . -name "*" -mtime +13+14 -print` )
set output = "`cmd $file ; set stat = $status`"
if ( $stat != 0 ) then
echo "cmd $file return -- $stat"
endif
echo $output
end

I can never remember if the $status of `cmd` is available after the SET statment completes or if it is over written by the set, that is why I put it in a local inside the back quote so I know it refers to completion status of the cmd and not the set.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top