3 ms·
Why use an alias in a script? Or in general? Functions work everywhere.
by RhysU 2y ago
Why use an alias in a script?
Or in general? Functions work everywhere.
- sudahtigabulan 2y agoI suppose aliases predated functions. Can't find a reference to support that, though. Just a possible reason. BTW aliases come from csh, and there they support arguments, which makes them similar to functions.
- oguz-ismail 2y agoAliases are like C macros $ alias foo='seq 3 | ' $ foo cat 1 2 3 Functions are functions
- RhysU 2y agoSo then use $variables for evil syntactic tricks? That works everywhere. Functions where hygiene counts? Aliases never?
- oguz-ismail 2y ago>use $variables for evil syntactic tricks Can't do that without eval, which is another can of worms. Aliases are fine
- metadat 2y agoFunctions don't work everywhere. Bash functions only work in the current shell context unless exported via an `export -f myfun' statement in between the function declaration and downstream sub-shell usage. Working example: pzoppin() { printf 'echo is for torrent scene n00bs from %s\n' "$*" trap "printf '%s\n' <<< \"$*\"" RETURN EXIT SIGINT SIGTERM } export -f pzoppin echo -e 'irc\0mamas donuts\0starseeds' \ | xargs -0 -n 1 -I {} /usr/bin/env bash -c ' echo hi pzoppin "$*" echo byee ' _ {} The above will fail miserably without the magic incantation: `export -f pzoppin' Why'd they design an otherwise perfectly usable, mapless language without default c-style global functions? :)