Home > Uncategorized > bash: create a function to handle arguments in the middle of a command line, unlike an alias

bash: create a function to handle arguments in the middle of a command line, unlike an alias

It’s quite easy to create a function that you can then call from bash that takes in arguments other than directly at the end (like an alias):

plugin_wizard() { cd /usr/share/ossim/scripts; ./plugin_wizard.pl $@ ; cd -; }

You can also treat each N argument as $N.

Advertisements
Tags: , ,
  1. lee
    December 20, 2012 at 12:05 pm

    I find subshells useful for preserving the current directory instead of your “cd -“. For instance:

    plugin_wizard() { (cd /usr/share/ossim/scripts; ./plugin_wizards.pl $@ ) }
    
    • December 20, 2012 at 12:08 pm

      Thanks very much for this! That looks great.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: