[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How pass arguments to a command run by the -c option of
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] How pass arguments to a command run by the -c option of bash? |
Date: |
Mon, 22 Jul 2013 08:06:14 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Sun, Jul 21, 2013 at 11:01:45AM -0500, Peng Yu wrote:
> I'm trying to run a command by the -c option. But 'a' is not passed to
> address@hidden Does anybody know what is correct way to pass the command
> arguments to a command run by the -c option of bash?
>
> ~$ bash -c 'echo x $@' a b c
> x b c
bash -c 'echo x "$@"' _ a b c
You need to put a placeholder in there to become $0.
More realistic example:
find . -type f -name '*.sh' -exec bash -c '
for f; do mv -i "$f" "${f%.sh}"; done
' _ {} +
Don't use "-" for the placeholder, because some commands interpret that
as a synonym for "--", and then it just vanishes. Likewise, don't use
"--" either. Almost anything else is fine.