You are not logged in.

#1 2018-09-07 02:42:42

super_trash
Banned
Registered: 2018-07-04
Posts: 50

Package name as input of an alias

From wiki: https://wiki.archlinux.org/index.php/Pa … l_packages

I have this command: pacman -Qi wget | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u

But I'd like to alias the above command but accept the package-name as input from user, how to?

Last edited by super_trash (2018-09-07 03:44:16)

Offline

#2 2018-09-07 03:01:22

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,541
Website

Re: Package name as input of an alias

Aliases do not take parameters, use a function:

somename() { pacman -Qi "$@" | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u; }

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2018-09-07 03:06:39

super_trash
Banned
Registered: 2018-07-04
Posts: 50

Re: Package name as input of an alias

Trilby wrote:

Aliases do not take parameters, use a function:

somename() { pacman -Qi "$@" | awk -F'[:<=>]' '/^Depends/ {print $2}' | xargs -n1 | sort -u; }

True, but I'd embed it to alias by adding `;somename` at the end.

Solved.

Offline

#4 2018-09-07 03:19:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,541
Website

Re: Package name as input of an alias

Why would you do that?  There's no reason to create a function just to create an alias to it.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2018-09-07 03:44:05

super_trash
Banned
Registered: 2018-07-04
Posts: 50

Re: Package name as input of an alias

Trilby wrote:

Why would you do that?  There's no reason to create a function just to create an alias to it.

I had trouble to alias now, can you help.

I try: alias cld='f() { pacman -Si "$@" | awk -F\'[:<=>]\' \'/^Depends/ {print $2}\' | xargs -n1 | sort -u };f'

but got error: parse error near `}'

I tried to escape ' character.


I need to put all pacman-things to one alias file.

Offline

#6 2018-09-07 03:59:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,541
Website

Re: Package name as input of an alias

You need a semicolon after 'sort -u' - but again, this makes no sense as an alias, just leave it a function.

EDIT: the semicolon is needed, but may not be sufficient.  I'm not sure exactly where the problem is, but I see no point in debugging a needlessly complex function definition within an alias.  Just define a function and be done with it.

Last edited by Trilby (2018-09-07 04:06:33)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2018-09-09 09:14:18

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Package name as input of an alias

Or use expac since it's super efficient and also not vulnerable to forgetting to use LC_ALL=C when using awk to match English strings:

expac -l '\n' '%E' wget| sort -u

Last edited by eschwartz (2018-09-09 09:14:57)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB