-2

Let's say I have a bash script called script.sh and I want to create an alias runscript. Now, I know how to create an alias in my bash_profile or bashrc.

However - if I want to run parameters and do the following

$ runscript param1 param2

Is there something special I need to write in the script or in the alias that allows me to run the alias and the use parameters as well?

user2656127
  • 655
  • 3
  • 15
  • 31
  • An alias cannot admin multiple parameters. In case of need, you can create a function to handle them, also in `.bash_profile` or `.bashrc`. – fedorqui Apr 02 '14 at 12:01
  • if your params going to the end of line, simple try `alias bubu=ls` and you can `bubu /etc /bin` for `ls /etc /bin` – clt60 Apr 02 '14 at 12:07
  • Sorry @jm666 I don't follow - can you elaborate slightly? – user2656127 Apr 02 '14 at 12:54
  • not really, because I said everything. if you do `alias bbb=ls` mean the `bbb` will be alias to `ls`. So when you run `bbb arg1 arg2` it is the same as `ls arg1 arg2`. For more advanced argument handling you should use shell functions, as told you already @fedorqui. You should always try the example and will see yourself. ;) – clt60 Apr 02 '14 at 12:59

1 Answers1

1

Based on your other question - "Accessing Shell parameters inside functions" - here is an example:

$ ls script
script
$ cat script
#!/usr/bin/env bash

_aFunction() {
    echo "Parameter 1: ${1}"
    echo "Parameter 2: ${2}"
}

_aFunction
_aFunction "$1" "$2"
_aFunction One Two

$ alias my_alias="./script"
$ my_alias 1 2
Parameter 1:
Parameter 2:
Parameter 1: 1
Parameter 2: 2
Parameter 1: One
Parameter 2: Two
Saucier
  • 4,200
  • 1
  • 25
  • 46