Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #255590

Re: alias in bash script issue

From David Wright <deblis@lionunicorn.co.uk>
Newsgroups linux.debian.user
Subject Re: alias in bash script issue
Date 2023-03-04 18:20 +0100
Message-ID <G5DI5-a3Xs-5@gated-at.bofh.it> (permalink)
References <G5vAR-9YKb-3@gated-at.bofh.it> <G5wQh-9ZrY-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sat 04 Mar 2023 at 20:52:15 (+1100), David wrote:

> Hi. Friends don't help friends to do bad things :)
> 
> Debian's default shell is 'dash'. Its manual, readable using 'man dash',
> says
> 
>     Aliases provide a convenient way for naive users to create shorthands
>     for commands without having to learn how to create functions with
>     arguments.

IMHO manpages should be about function, not policy. I don't like
this condescension. man bash   is more straightforward:

  For almost every purpose, aliases are superseded by shell functions.

> They can also be used to create lexically obscure code.

What has that got to do with the price of fish?

In view of the Obfuscated Perl Contest, is the author railing
against writing anything in Perl?

>     This use is discouraged

There's a place for warning about the use of aliases in, say,
Greg's BashPitfalls, or books, but not here.

> To achieve your goal, do this instead.
> 
> In .bash_profile, replace the line
>   alias k='minikube kubectl --'
> 
> with these two lines:
>   k() { minikube kubectl "$@" ; }
>   export k

Overkill for those I've written. And I would discourage the use
of that sort of shortcut function anywhere else but interactively.
Exporting it and then using it in scripts is going to produce
code that's just as lexically obscure.

I guess it falls to me to provide some examples of mine:

  alias 1234='printf AmexD\\n'

Redacted; one of several. (I don't have an American Express card.)

  alias cal='ncal -3 -A1'

For me, cal output needs transposing. This range is so useful.

  alias cdeject='eject # mask cdeject which produces I/O error and locks up drive'

From the days when I played red-book CDs at work.

  alias hekspace='od -t a -t x1 -An'

Can anyone memorise all those switches.

  alias py='python3'

A sophisticated calculator.

  alias tnef='tnef -v --directory ~/Documents --number-backups'

Curse MS Exchange's attachments.

Finally, I'm not arguing against manpage warnings like this:

  --drq-hsm-error
    VERY DANGEROUS, DON'T EVEN THINK ABOUT USING IT. …
    … VERY DANGEROUS, DO NOT USE!! 

  (man hdparm)

that guard against accidental bricking.

Cheers,
David.

Back to linux.debian.user | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

alias in bash script issue Ken Young <ken@highwinds.cloud> - 2023-03-04 09:40 +0100
  Re: alias in bash script issue David <bouncingcats@gmail.com> - 2023-03-04 11:00 +0100
    Re: alias in bash script issue Tom Furie <tom@furie.org.uk> - 2023-03-04 14:20 +0100
      Re: alias in bash script issue David <bouncingcats@gmail.com> - 2023-03-04 15:50 +0100
        Re: alias in bash script issue Greg Wooledge <greg@wooledge.org> - 2023-03-04 17:30 +0100
    Re: alias in bash script issue David Wright <deblis@lionunicorn.co.uk> - 2023-03-04 18:20 +0100
      Re: alias in bash script issue Greg Wooledge <greg@wooledge.org> - 2023-03-04 18:30 +0100
        Re: alias in bash script issue David Wright <deblis@lionunicorn.co.uk> - 2023-03-05 21:40 +0100
          Re: alias in bash script issue Greg Wooledge <greg@wooledge.org> - 2023-03-05 22:40 +0100
            Re: alias in bash script issue David Wright <deblis@lionunicorn.co.uk> - 2023-03-07 03:50 +0100
    Re: alias in bash script issue Ken Young <ken@highwinds.cloud> - 2023-03-05 02:30 +0100
      Re: alias in bash script issue Greg Wooledge <greg@wooledge.org> - 2023-03-05 02:40 +0100
        Re: alias in bash script issue Tom Browder <tom.browder@gmail.com> - 2023-03-05 12:30 +0100
          Re: alias in bash script issue Ken Young <ken@highwinds.cloud> - 2023-03-05 12:40 +0100
            Re: alias in bash script issue Tom Browder <tom.browder@gmail.com> - 2023-03-05 12:50 +0100
              Re: alias in bash script issue Nicolas George <george@nsup.org> - 2023-03-05 14:30 +0100
                Re: alias in bash script issue <tomas@tuxteam.de> - 2023-03-05 17:10 +0100
                Re: alias in bash script issue Tom Browder <tom.browder@gmail.com> - 2023-03-07 13:10 +0100
            Re: alias in bash script issue <tomas@tuxteam.de> - 2023-03-05 14:10 +0100
  Re: alias in bash script issue Yassine Chaouche <a.chaouche@algerian-radio.dz> - 2023-03-06 11:10 +0100

csiph-web