ls -l | awk '/.*/ { print $8}' | xargs -n1 -I{} gcc -o {}.o -g {}
long list the current directory with detail, take the last column with awk which contains a list of names, take each name and execute "gcc -o
xargs can print the command that is being generated using the -t option, or -p option for you to confirm each command that will be executed on the file. The -I{} indicates a special symbol {} is going to be used for the location where the symbol name should be put into instead of the default at the end of the command. the -n
xargs called without any command will act the same as an echo command.
It is essentially an easy replacement for for loops in a shell script
No comments:
Post a Comment