Inconsistent output from Bourne Shell "type" command

Bug #509128 reported by Victor Engmark
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dash (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

Binary package hint: coreutils

I just found that two subsequent calls of "type bash" resulted in two different results. Here's the complete verbatim (anonymized BASH PS1) output from the session:
user@machine:~/path (master)$ sh
$ type foo
foo: not found
$ type bash
bash is /bin/bash
$ type foo
foo: not found
$ echo $1

$ type foo
foo: not found
$ echo $?
127
$ type bash
bash is a tracked alias for /bin/bash
$ type bash
bash is a tracked alias for /bin/bash
$ type foo
foo: not found
$ type service
service is /usr/sbin/service
$ type -t bash
-t: not found
bash is a tracked alias for /bin/bash
$

Tags: bourne-shell
Revision history for this message
C de-Avillez (hggdh2) wrote :

Thank you for opening this bug and helping make Ubuntu better.

I am unsure why you selected 'coreutils' as the target package here; I am tending to assign it to dash, but I want to be sure.

Please:

1. run 'lsb_release -a' ;
2. run 'ls -l /bin/sh'

Please post the output here.

Thank you.

p.s. I can confirm your findings for dash version 0.5.5.1-3ubuntu1 on Lucid.

Changed in coreutils (Ubuntu):
status: New → Incomplete
Revision history for this message
Victor Engmark (victor-engmark) wrote :

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2009-07-30 13:07 /bin/sh -> dash

Revision history for this message
C de-Avillez (hggdh2) wrote :

Thank you. I am resetting the affected package to dash, then, and marking it Confirmed/Medium.

cerdea@xango:~$ sh
$ type bash
bash is /bin/bash
$ echo $?
0
$ type bash
bash is a tracked alias for /bin/bash
$ echo $?
0
$ type grumpa
grumpa: not found
$ echo $?
127
$ type grumpa
grumpa: not found
$ echo $?
127
$ apt-cache policy dash
dash:
  Installed: 0.5.5.1-3ubuntu1
  Candidate: 0.5.5.1-3ubuntu1
  Version table:
 *** 0.5.5.1-3ubuntu1 0
        500 http://archive.ubuntu.com lucid/main Packages
        100 /var/lib/dpkg/status
$

affects: coreutils (Ubuntu) → dash (Ubuntu)
Changed in dash (Ubuntu):
importance: Undecided → Medium
status: Incomplete → Confirmed
Revision history for this message
Jilles Tjoelker (jilles) wrote :

I don't consider this a bug.

Given you say "Bourne shell", see this session with an original Bourne shell (Heirloom toolchest jsh, close to Solaris 10 /bin/sh):

$ type ls
ls is /bin/ls
$ type ls
ls is /bin/ls
$ ls /
COPYRIGHT dev home proc tmp
bin dist lib rescue usr
boot entropy libexec root var
cdrom etc media sbin
compat extra0 mnt sys
$ type ls
ls is hashed (/bin/ls)

The output of the type builtin is not fixed as "utility is pathname". It may show additional information such as whether the command is in the cache of known utilities (often known as "hash" or "tracked aliases"). This can be useful to know because the shell will not notice a new 'ls' placed in a directory that precedes /bin in PATH in the above example.

Apparently dash's type builtin may add things to this cache, but the original Bourne shell's does not.

To get output that can be interpreted with a program, use command -v. (For completeness, the original Bourne shell does not support this, and will likely find a /usr/bin/command which is a script interpreted by a modern shell containing the equivalent of ${0##*/} "$@".)

Revision history for this message
Victor Engmark (victor-engmark) wrote :

@Jilles: The mention of "Bourne Shell" was in error, because I didn't know at the time that /bin/sh was Dash.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.