Sponsored Content
Top Forums Shell Programming and Scripting Book and Links about Shells; and zsh question Post 302405884 by alister on Saturday 20th of March 2010 01:09:27 PM
Old 03-20-2010


---------- Post updated at 01:09 PM ----------

Actually, I just now noticed the "zsh" part of the subject, checked and saw that zsh (which I have zero experience with) does have a "which" builti-in. My apologies, jim_mcnamara, for jumping the gun. I had assumed you were referring to the common (though I don't think posix standardized) which(1) executable found on most BSD and Linux systems.

I will leave my original post (which follows) as is, as I think it may prevent misunderstandings among those who (like me) do not use zsh.


---------- Posted at 12:35 PM ----------


Quote:
Originally Posted by jim mcnamara
Code:
which echo

tells you whether the echo you ran is builtin or not.
That's incorrect. which(1) will search $PATH directories for an executable. If it finds anything, it will always be an external executable.

Use type to see what is actually being run.

Code:
$ which echo
/bin/echo
$ type echo
echo is a shell builtin
$ type -a echo
echo is a shell builtin
echo is a tracked alias for /bin/echo

The first result from the type built-in is what the shell will actually use. There are ways to use something other than the first found option, read your shell's man page.

Also, on ksh variants, instead of type use whence (although it may have type aliased to whence -v already as a convenience):
Code:
$ ksh --version
  version         sh (AT&T Labs Research) 1993-12-28 p

$ alias type
type='whence -v'

Regards,
Alister

Last edited by alister; 03-20-2010 at 03:17 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

basic question about shells?

I have come across the topic of changing shells, does that mean that all Unix operating systems comes with a variety of shells built in and its up to the user to select a shell of his/her choice? (2 Replies)
Discussion started by: wmosley2
2 Replies

2. UNIX for Dummies Questions & Answers

A question for links in Unix

Is there a command that I can list, at once, all the links(path) of a give file ( including hard link and soft link)? If not, can it be down by writing a script? Thanks a lot. (I know that pwd would only list one path.) (2 Replies)
Discussion started by: nj302
2 Replies

3. UNIX for Dummies Questions & Answers

Question posting links

Hi, I do not want to violate any rules, so thought to ask before posting any links. Just to contribute to the forum: through surfing I found a link to download "Unix in a Nutshell" (*.chm) FREE. I was wondering if I can post that link here. Thanks Hemang (5 Replies)
Discussion started by: hemangjani
5 Replies

4. UNIX for Dummies Questions & Answers

question about zsh

hi, In bash, $ bind -P | grep yank-last yank-last-arg can be found on "\M-.", "\M-_". this allows me to press ALT key and the period (.) to yank the last argument of the previous command line into the current command line. How can I get the same behavior in zsh ? Thanks ... (0 Replies)
Discussion started by: Andrewkl
0 Replies

5. Shell Programming and Scripting

Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers: #!/bin/bash #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #set log number #i=1 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #Check if log exits, if so incrememnt log number up so we don't clobber #while... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

6. UNIX for Dummies Questions & Answers

A Basic Question About Links

How can you tell if a file is linked to another file?????? Do not title posts "Urgent", etc. Per forum rules. (3 Replies)
Discussion started by: BIGGDRE10
3 Replies

7. UNIX for Dummies Questions & Answers

Soft links question

Hello. I have some main directories. For example : /main_dir1 /main_dir2In main_dir2, I have a sub dir named sub_dir2-1 with 2 files in it ( file_2-1, file_2-2 ) /main_dir2sub_dir2-1file_2-1 file_2-2From "/main_dir1/A/B/C" I make a soft link ln -s /main_dir2/sub_dir2-1 ... (6 Replies)
Discussion started by: jcdole
6 Replies

8. Shell Programming and Scripting

Zsh array -a vs. -A question

Inside a zsh function, I create a local array with local -a arrayname and a local associative array with local -A arrayname. I also can create an array using set, like this: set -A arrayname value1 value2 value3In this form, I can not explicitly declare that an array is associative or... (2 Replies)
Discussion started by: rovf
2 Replies

9. Programming

Question regarding a book for C++

Hi all. A course I am has Beginning C prescribed for our C++ work, but I am wondering, is this correct? Why not Beginning C++ by the same author? We code in C++ and learn C++, when starting a project in Code::Blocks we select C++. I may just be confused. Thanks for the help. (1 Reply)
Discussion started by: AnthonyWall56
1 Replies
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. SunOS 5.10 30 Aug 2004 getusershell(3C)
All times are GMT -4. The time now is 10:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy