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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -