How to set GNU Indent input

I use GNU indent and I want using bash script to give a command that takes as input all my C files(*.c, *.h) and gives output these files formatted with Indent.

My command line is

indent | find -regex '.*/.*\.\(c\|h\)$' | xargs

Is not working,it stacks.

Upvotes: 2

Views: 273

Answers (1)

Inian
Inian

Reputation: 85800

You are incorrectly passing the arguments to indent command. Your command is just left waiting for inputs over standard input but you haven't provided any. May be your intention was to run the command on each result from the find command, which should have been written as

find -regex '.*/.*\.\(c\|h\)$' -print0 | xargs -0 indent

In pure bash you just need to pass them as positional parameters. If the source and header files are in a directory, without nesting, a simple glob expansion would suffice

indent *.c *.h

For multi-level directory structure, you can use find

find -regex '.*/.*\.\(c\|h\)$' -exec indent {} +

Upvotes: 1

Related Questions