1824485 Members
3416 Online
109671 Solutions
New Discussion юеВ

Internal commands

 
Shahul
Esteemed Contributor

Internal commands


Hi all,

Is there anything called internal commands in HP Unix? I have renamed /usr/bin/ls to ls.old, still ls is listiing the directory. Where from this ls is getting executed?

TIA
Shahul
15 REPLIES 15
melvyn burnard
Honored Contributor

Re: Internal commands

Yes there are certain commands built-in to the shell, but cannot remember too many of them ;-}
If you wish to check where you are sourcing a command, you can always do:
whence
for example
root @uksd3 #whence date
/usr/bin/date

I do know cd is one of hte built-ins, and here is an example
root @uksd3 #whence cd
cd

My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Sunil Sharma_1
Honored Contributor

Re: Internal commands

Hi,
there is lots of Internal Commands in Unix whihc is part of shell basically.
like cd
ls is external command you can find out which ls is getting excuted using which command
#which ls

you will get answer.....

sunil
*** Dream as if you'll live forever. Live as if you'll die today ***
RAC_1
Honored Contributor

Re: Internal commands

Some commands are built into shell. These are called internal.

Check as follows.

whence ls
type ls(type is a internal command in ksh)
which ls
There is no substitute to HARDWORK
Shahul
Esteemed Contributor

Re: Internal commands


Hi,

which ls is giving /usr/bin/ls output. Even if I rename this, ls command works. Don't know where from this?

Thanks and regards
Shahul
Massimo Bianchi
Honored Contributor

Re: Internal commands

Hi,
i know to be a bit late...

From man csh you get a full list of the built-in commands.

From man ksh you don't get the list, they are talked about here and there.

Massimo

Pete Randall
Outstanding Contributor

Re: Internal commands

Shahul,

Most likely you're picking up /sbin/ls.


Pete


Pete
melvyn burnard
Honored Contributor

Re: Internal commands

I believe Pete is correct, as a whence ls on my box does give this as the path, but which ls still shows /usr/bin/ls
There is also no man page for whence, so I suspect/believe that whence is one of htose built-in commands that I had forgotten ;-]
Interestingly, if you start a ksh, and then do a whence ls, this DOES show /usr/bin/ls

My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Radhakrishnan Venkatara
Trusted Contributor

Re: Internal commands

shahul,

it does take from /sbin/ls.

internal commands are varies according to the shells.

here are some.it may not be same in all shells and in all unix flavours.

: (colon) exec shift
. (dot) exit times
break export trap
continue readonly wait
eval return

how are u ?

radhakrishnan
Negative thinking is a highest form of Intelligence
Sunil Sharma_1
Honored Contributor

Re: Internal commands

Hi,

if output of "which ls" /usr/bin/ls
it means in /usr/bin directory ls is there
just check it once again.
and just post the output of
whereis ls

command


Sunil
*** Dream as if you'll live forever. Live as if you'll die today ***
Bill Hassell
Honored Contributor

Re: Internal commands

The commands 'which' and 'whereis' are not useful in determining where a command will be found. The shell has many builtin's, namely cd and ls. which and whereis do NOT follow the same rules in looking for something to execute as the shell uses. And it is important to know that there MAY be slightly different beavior between the external command and a shell built-in. As mentioned, whence is the command to use but the best command is 'type' (an alias to whence -v, so use this: type type). ALWAYS use 'type' to determine what will happen when you type a particular string of characters. which and whereis know nothing about shell builtins and aliases. Try these:

type ls
type cd
type pwd
type fc
type for

For instance, which and whereis have no idea what 'for' might be, but 'type' (whence -v) definitely knows. Many shell built-in commands are found in /usr/bin but are simple shell scripts with the shell built-in:

cat /usr/bin/ulimit
type ulimit

There are also situations where the external command is better than the shell built-in:

cd /usr/spool/lp
pwd
/usr/bin/pwd

You'll see that the built-in pwd remembers how you got to the /usr/spool/lp (the legacy directory for the spooler, which is a symlink) but /usr/bin/pwd shows the 'real' directory (/var/spool/lp).

The 'whence' (and 'type') commands are part of POSIX shells such as /usr/bin/sh and /usr/bin/ksh (and bash if you added that shell).


Bill Hassell, sysadmin
Jerome Baron
Respected Contributor

Re: Internal commands

ls is in different directory :
/bin
/sbin
/usr/bin

Regards,
Jerome
Rory R Hammond
Trusted Contributor

Re: Internal commands

The commands we execute are deteremed by PATHS. Listed is a copy of my
wh command. which is also linked as whall in my user local bin.

#!/bin/sh
#ident "@(#) Rory Hammond - - /usr/local/bin/wh"
# 07-11-93 replaced C program with this shell
#
# wh
#
# Examine the path for a command & tell which dir has it. Stop with
# the 1st dir that has it.
#
# whall link whall to wh and it will find all occurance in the paths
#

if [ $# -eq 0 ]
then
echo "usage:\t$0 prognam ...." | sed -e 's/\/\//\//g'
exit 1
fi

dirs=`echo $PATH |
sed -e 's/^:/.:/' -e 's/:$/:./' -e 's/::/:.:/' -e 's/:/ /g'`

notfound=

for ffile in $*
do
found=0

for dir in $dirs
do
if [ -x ${dir}/${ffile} -a ! -d "${dir}/$1" ]
then
echo "${dir}/${ffile}"| sed -e 's/\/\//\//g'
found=1
if [ $0 = "whall" ]
then
break
fi
fi
done

if [ ${found} -eq 0 ]
then
notfound="${notfound} $1"
fi

shift
done

#report the not found

for arg in $notfound
do
echo "${arg} not found"
done

exit 0

There are a 100 ways to do things and 97 of them are right
Hai Nguyen_1
Honored Contributor

Re: Internal commands

Shahul,

You might have picked up /sbin/ls.

# whereis ls

shows the paths of ls.

Removing sbin from the path will stop ls from working in your case.

Hai
Rory R Hammond
Trusted Contributor

Re: Internal commands

I am very sorry, posted the incorrect source to wh.

Whereis shows all occurance. The shell script shows which one you are executing

The man pages do describe commands. One of the problems that you encounter alias will fool you path

alias ls="/sbin/ls -l"

man sh-bourne lists the "special commands"

rory

#!/bin/sh
#ident "@(#) Rory Hammond -menlo - /usr/local/bin/wh"
# 07-11-93 replaced C program with this shell
#
# wh
#
# Examine the path for a command & tell which dir has it. Stop with
# the 1st dir that has it.
#
#

if [ $# -eq 0 ]
then
echo "usage:\t$0 prognam ...." | sed -e 's/\/\//\//g'
exit 1
fi

dirs=`echo $PATH |
sed -e 's/^:/.:/' -e 's/:$/:./' -e 's/::/:.:/' -e 's/:/ /g'`

notfound=

for ffile in $*
do
found=0

for dir in $dirs
do
if [ -x ${dir}/${ffile} -a ! -d "${dir}/$1" ]
then
echo "${dir}/${ffile}"| sed -e 's/\/\//\//g'
found=1
break
fi
done

if [ ${found} -eq 0 ]
then
notfound="${notfound} $1"
fi

shift
done

#report the not found

for arg in $notfound
do
echo "${arg} not found"
done
There are a 100 ways to do things and 97 of them are right
John Meissner
Esteemed Contributor

Re: Internal commands

if... as an example you were executing "ls" as many people are using....

type ls

this will show you where the ls command was executed from.

if you are concerned that it might be an aliased command try this

alias

this will show you a list of all aliases you have assigned.

All paths lead to destiny