[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

scripts, was Re: TBird mail



On Wed 07 Dec 2022 at 07:56:53 (-0500), rhkramer@gmail.com wrote:
> On Wednesday, December 07, 2022 07:18:57 AM Greg Wooledge wrote:
> > Here's my version:
> > 
> > rlart() {
> >   local day time path
> >   find "${1:-.}" -type f -printf '%T@ %TY-%Tm-%Td %TT %p\0' |
> >     sort -zn |
> >     while read -rd '' _ day time path; do
> >       printf '%s %s %s\n' "$day" "${time%.*}" "$path"
> >     done
> > }
> 
> I wonder if youi could expound somewhat on that:
> 
> (Aside: although I use bash, and have written a few simple scripts, I am by no 
> means a bash guru.)
> 
>    * Might I infer that you have some large bash (presumably) script (file) 
> containing various functions (e.g., rlart) to perform a variety of tasks?
> 
>    * If so, how do you invoke those functions (I mean the syntax) -- I guess 
> it would be something like:
> 
> $ <name of script file> rlart(<parameter(s)>)

Greg has pasted a bash function as it is defined in a startup file,
presumably ~/.bashrc. If he were to   type rlart   then you'd see
semicolons at the ends of lines.

Yes, .bashrc gets very large as you add more command definitions;
I split mine up, with separate files for handling caddies/sticks/cards,
transfers between my PCs, and browsers/web-related, plus each host
has its own .bash-1-$HOSTNAME and .bash-9-$HOSTNAME sourced at the
start and end for host-specific configuration. I treat ~/.xsession
and ~/.fvwm/ files the same way. Not forgetting the file that
handles colouring and prompts. About 7000 lines common to all hosts,
with .bashrc containing around 350 functions. Many of these are
variants of one another, of course.

By way of an example, if the file contains:

  function installer-on {
      [ -z "$1" ] && msgerr "Usage:       ${FUNCNAME[0]} hostname [username]
          runs ssh to connect to the installer on host hostname which should be
          running the network-console. It avoids polluting your known_hosts file
          with the ephemeral host key being used by the installer." && return 1
      ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null "${2:-installer}"@"$1"
  }

then:

  $ type installer-on
  installer-on is a function
  installer-on () 
  { 
      [ -z "$1" ] && msgerr "Usage:       ${FUNCNAME[0]} hostname [username]
          runs ssh to connect to the installer on host hostname which should be
          running the network-console. It avoids polluting your known_hosts file
          with the ephemeral host key being used by the installer." && return 1;
      ssh -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null "${2:-installer}"@"$1"
  }
  $ 

and to use it, saving a lot of typing:

  $ installer-on acer
  ssh: connect to host acer port 22: No route to host
  $ 

Obviously I'm not running the debian-installer at the moment, nor
is acer even switched on. But the second argument has its uses:

  $ installer-on localhost auser
  The authenticity of host 'localhost (::1)' can't be established.
  ECDSA key fingerprint is SHA256:0123456789abcdefghijklmnopqrstuvwxyz0123456.
  Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
  Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
  Linux axis 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64
  
  The programs included with the Debian GNU/Linux system are free software;
  [ … ]

Despite the "Permanently added" warning, it has in fact been thrown away.

--

> A speaker who uses ahhs, ums, or such may have a real physical or mental 
> disability, or may be showing disrespect for his listeners by not properly 
> preparing in advance and thinking before speaking.  (Remember Cicero who did 
> not have enough time to write a short missive.)  (That speaker might have been 
> "trained" to do this by being interrupted often if he pauses.)

Margaret Thatcher is a prime example, even making the pages of Nature:

https://www.nature.com/articles/300744a0

Of course, an initial "Er…" can be an important cue that you're going
to say something. Without it, someone not paying attention to you will
likely miss the first part of your utterance, or at least have to
replay it in their head before comprehending it. I believe our replay
mechanism has been much researched.

Cheers,
David.

Reply to: