0

I'm trying to make an alias to a binary to ensure I'm using the latest version. Though I'm unable to propagate arguments

I'd to call it like so: script --arg first-argument

# One-liner splitted into several lines in order to make it more intelligible # I consider using `| sort -V | tail -1` to sort, I'm new to `awk` and realize how weak this might be alias script="ls -alh /path/to/ruby/gems/ | \ grep -E script-[0-9].[0-9].[0-9]+ | \ awk 'END{split(\$9,a,\"-\"); print \"/path/to/ruby/gems/script-\"a[2]\"/bin/script\"}' | \ bash $@" 

To simplify, the problem would be the same with the following:

alias script="echo '/path/to/some/script' | bash <arguments>" 

Hadn't any success with $@, $*, "$@", "$*" or xargs, could you help me ?

0

1 Answer 1

1

alias appends the arguments by default. If you want to explicitly specify them, use a function.

script() { ls -alh /path/to/ruby/gems/ | grep -E script-[0-9].[0-9].[0-9]+ | awk 'END{split(\$9,a,\"-\"); print \"/path/to/ruby/gems/script-\"a[2]\"/bin/script\"}' | bash "$@" } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your feedback, it's never too late to learn about bash functions I guess...! I'm still trying, though your suggestion (minus the " after $@) returns bash: --arg: invalid option
@Sumak One " was missing. Anyways, the error --arg: invalid option is caused when you call script --arg because --arg is not an option for bash. Could it be that you actually want to execute bash /path/to/ruby/gems/... "$@" instead of echo /path/to/ruby/gems/... | bash "$@"?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.