Skip to content

Instantly share code, notes, and snippets.

@kne42
Created August 27, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kne42/7a8ce87e7e3d1088009a707bef263a1c to your computer and use it in GitHub Desktop.
Save kne42/7a8ce87e7e3d1088009a707bef263a1c to your computer and use it in GitHub Desktop.
Getting Full Command Line with Bash

Preface

Sometimes you need the input exactly as written - for example if you want to be able to tell the difference between bar and b"a"r.

The following is a workaround/hack to retrieve the full command that executed your script.

Step 1

Rename your script to add a leading underscore to it. For example, foo becomes _foo.

Step 2

Create an alias in your ~/.bash_rc or /etc/profile replacing %NAME% with the name of your script:

alias %NAME%='function _pass(){ echo `history 1` | grep -o '%NAME%.*' | _%NAME%; }; _pass'

Example:

alias foo='function _pass(){ echo `history 1` | grep -o 'foo.*' | _foo; }; _pass'

Now your script receives the whole command line that it was called from!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment