2

I realise this might be a stupid question, but I've been trying to follow the advice on the following post https://stackoverflow.com/questions/16928004/how-to-enter-ssh-password-using-bash

However, I've come up to a problem. I installed expect with sudo apt-get install expect but now embarrassingly I can't figure out where the script interpreter is. It doesn't seem to be in the normal paths where people look to (i.e /bin/ or /usr/bin/ ).

It does seem to have installed, since $ expect seems to work, but I just can't use the interpreter (i.e I try to shebang it like everyone else with #!/bin/sh/expect and it gives an error).

Community
  • 1
  • 1
Marses
  • 1,464
  • 3
  • 23
  • 40
  • 2
    `which expect`? – Dusan Bajic Oct 28 '16 at 16:28
  • 1
    @DusanBajic, better to suggest `type expect`; `which` doesn't know about aliases, functions, or otherwise anything but the PATH, so if the command the user is able to run interactively isn't coming from a binary in the PATH, `which` won't be able to find it. – Charles Duffy Oct 28 '16 at 16:37

2 Answers2

4

You can find the location by listing all the files the package expect provides by dpkg -L:

dpkg -L expect

or narrow it down to only the filenames ending in expect:

dpkg -L expect | grep '/expect$'

or if resides in typical binary directories:

dpkg -L expect | grep -E '/s?bin/'

Also the typical way to go through the $PATH for an executable is to use:

which expect

or better (considering shell internals), not strictly needed in this case though:

type -a expect
heemayl
  • 39,294
  • 7
  • 70
  • 76
1
whereis expect

... (you could have guessed it ;)

Alex
  • 5,759
  • 1
  • 32
  • 47
  • 2
    `whereis`, like `which`, is an external command. Better to suggest `type`, which has the shell do its own lookup -- and will thus honor aliases, functions, etc -- and additionally avoids the startup overhead for running an external command. – Charles Duffy Oct 28 '16 at 16:35
  • @CharlesDuffy true, except it won't return the command/location when it is an alias. – Alex Oct 28 '16 at 20:38
  • sure, but `whereis` won't necessarily even tell you *what the external command is* that's actually being run when the user types `expect` at their prompt. Maybe they have `alias expect=expect1.1` defined; if the actual binary is something other than `expect`, then `whereis` is useless. (OTOH, if one *wants* to return only external commands, `type -P` will do that). And `type -a`, as suggested by heemayl, will return external commands *in addition to* aliases. – Charles Duffy Oct 28 '16 at 20:41