NetBSD-Users archive

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

Re: ssh-agent on 32-bit NetBSD?



    Date:        Mon, 23 Nov 2026 13:43:56 -0600
    From:        Ted Spradley <tsprad%talent-free-studios.com@localhost>
    Message-ID:  <20261123134356.c5f3b9e7b36b381e75671fb2%talent-free-studios.com@localhost>

  | Now I am seriously confused:
  |
  | set$ echo $SSS                                            
  |
  | set$ test -S "$SSS" && printf "it (%s) is a socket\n" $SSS
  | set$ [ -S "$SSS" ] || printf "it (%s) is a socket\n" $SSS 
  | it () is a socket
  | set$ 

Yes, one of those had to print that.

  | smoothie$ [ -S "$SSS" ] || printf "it (%s) is a socket\n" $SSS
  | it () is a socket
  | smoothie$ test -S "$SSS" || printf "it (%s) is a socket\n" $SSS  
  | it () is a socket
  | smoothie$ test -S "$SSS" && printf "it (%s) is a socket\n" $SSS

All how I would expect it to work, except the message from the first
two of those (which are more or less identical, whether you use [ ... ]
or test ...  is purely a style choice) is backwards, those are testing
that it is not a socket, not that it is (that is, the test is testing
for a socket, the printf happens when the answer is "no")

  | It works the same on both, so it's actually been wrong on both?

Wrong in what sense?   The code you showed, aside from the possible ~~
in there, looked more or less reasonable to me.

  | At the
  | bottom of page 67 of my Bolsky and Korn it says "|| Runs the command
  | following the || only if the command preceding the || returns False.  &&
  | Runs the command following the && only if the command preceding the &&
  | returns True"

That is how they work.   Not relevant here, as there was nothing doing
this, but also remember for the future that chains of || and && (which
can be intermingled) just run left to right (no operator precedence).
and "next command" means up to the next of those operators (or the end
if there is no more).   When the next command is not run, just skip
to the next operator, and do all the same again - the "preceding command"
is always the last one actually executed, not the one immediately to
the left of the operator (the leftmost command is always executed).
(You can use '{' '}' grouping to impose some operator precedence, such
a thing (group, or list) counts as one command - and can contain its
own and-or list (the name for a list of commands with && and/or ||
operators between them inside it.

So,  cmd1 || cmd2 || cmd3 || cmd4   just runs the commands one after
another until one of them works, then it runs no more of them

And  cmd1 && cmd2 && cmd3 && cmd4   runs the commands one after another
until one of them doesn't work (returns false - any exit status except 0)
and then runs no more.

Mixing && and || in one and-or list is legitimate, but you can easily
lose track of what it all really means, but two simple cases are

	cmd1 && cmd2 && cmd3 && ... || fail-cmd

That is, run cmd1, and if that works, cmd2, and if that also works cmd3.
If any one of them fails, and only if one of them does, then run
fail-cmd (no more of the cmdN commands).

And
	cmd1 || cmd2 || cmd3 || ...  && good-cmd

Which means try cmd1, then cmd2, then cnd3 (etc) until one of them
works (returns true - exit status 0).   One one has been found,
and only if 1 of them works, then run good-cmd, skipping all the
other cmdN commands.

Start mixing them up in more complex ways than that, and you
need to work out what happens for youself!


The original code you sent is intended to work like:

sagent(){
    [ -S "$SSH_AUTH_SOCK" ] || export SSH_AUTH_SOCK="$(< ~~/.ssh/ssh-agent.env)"

if SSH_AUTH_SOCK doesn't contain the file name of a socket
then set it by reading from that file name (and that ~~ there
still looks very odd).   Don't try it like that with the NetBSD sh,
not only will ~~ certainly not work, but $(< file) isn't a
shorthand for $(cat file) either.

    # if cached agent socket is invalid, start a new one
    [ -S "$SSH_AUTH_SOCK" ] || {

Again, if SSH_AUTH_SOCK is not a socket, then do these
commands:

        eval "$(ssh-agent)"

That one should start the agent, which will write sh commands
(using -s will force it to use Bourne shell style commands, rather
than csh type) to set SSH_AUTH_SOCKET (and more) if it all works properly.

ssh-agent must be a command you can find in your PATH of course.

        ssh-add

That (according to its man page) adds keys to the agent

        echo "$SSH_AUTH_SOCK" > ~/.ssh/ssh-agent.env

Then save the name of the socket to the file you intended to read
it from, ready for next time (just one ~ in this case, much more
rational).

    }
}

What actually happens when you run this?

Stick that small piece of code in a file, and run it like

	ksh -x /file/name     (just file-name if it is in '.')

(if the function wrapper is included, then you also need the
command to call the function defined there, or you can just put
the insides of the function into that file.)

and then, if that doesn't make clear what is happening, send
the output from that.    Note that running it this way probably
won't make an actual usable ssh-agent, but if something is going
wrong it might be possible to tell why.

Or try it with sh instead (just change that "$(<" into "$(cat "
first, that should be acceptable to either shell).

kre



Home | Main Index | Thread Index | Old Index