why xargs cannot receive argument -


i have sql files , want dump local db, first used shell command , not work

ls *.sql|xargs -i mysql -uroot -p123456 foo < {} zsh: no such file or directory: {} 

but below work

echo hello | xargs -i echo {} world hello world 

so why first command not work?

redirections handled shell before commands run. if want xargs handle redirection, need run subshell.

ls *.sql | xargs -i sh -c 'mysql -uroot -p123456 foo < {}' 

however, should not using ls drive scripts. want

for f in *.sql;     mysql -uroot -p123456 foo <"$f" done 

or quite possibly just

cat *.sql | mysql -uroot -p123456 foo 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -