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
Post a Comment