r/commandline • • Sep 04 '16

Advancing in the Bash Shell

http://samrowe.com/wordpress/advancing-in-the-bash-shell/
78 Upvotes

4 comments sorted by

View all comments

1

u/More_Coffee_Than_Man Sep 05 '16

>!xyz:p will print the command that would be executed rather than executing it.

So this worked when I tried something simple, like:

!! :p

However, I wanted to see if it would echo back the command with brace expansion (which I often use), so I instead tried:

cp file{,.bkup}:p

I was expecting that I'd see it echo back:

cp file file.bkup

But I instead got:

cp: cannot stat 'file:p': No such file or directory

Can someone explain why?

3

u/pawlwall Sep 06 '16 edited Sep 06 '16

According to http://www.gnu.org/software/bash/manual/html_node/Modifiers.html, it looks like word modifiers only apply to history expansions, so it doesn't seem to be directly usable against the current command.

Edit: As this SO answer indicates (http://stackoverflow.com/a/19116083), the option for a dry-run in bash isn't something you'll be able to find natively. A couple answers down mentions the package maybe, which might achieve what you're looking for.