|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Unexpected command/filename substitution ( caused by alias?)
Hi:
there is a shell script, with the name "foo", located in a bin directory. in the same time, there is an alias "foo='/path/bin/foo' ", just for convenience. in my home directory, there is a different script with name "foo" too. (a modified version.) while in my home directory, when I do: >$ cat foo my local "foo" is displayed, as expected. but if I do: >$ source foo, the common "/path/bin/foo" gets picked up, not my local one, as if the alias "foo" kicks in and substitutes the common "foo" for my local one. to source my local "foo", I have to explicitly say: >$ source ./foo what I don't get is, the "foo" is the filename argument for both "cat" and "source" commands, but why the "foo" alias seemingly kicks in in "source" command, not the "cat" command. Could any one shed some light on this? Thanks. NB Phil |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
source is command to execute other shell commands, so if you say
source foo it will try to run the command foo (alias in this case) If foo is a script why are you using source command to run it....cant you just dot in? . ./foo |
| The Following User Says Thank You to grep_me For This Useful Post: | ||
phil518 (02-28-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
The cat utility is being asked to read a file; the source utility is being asked to execute a file. When you execute a file, lots of additional processing is invoked to find the file to be executed (alias searches, $PATH searches, ...) that is not done when you are just reading a file.
|
| The Following User Says Thank You to Don Cragun For This Useful Post: | ||
phil518 (02-28-2013) | ||
|
#4
|
|||
|
|||
|
Thanks for all your responses.
I just found this detail info, which confirms your explanation: ". (source or dot operator) If filename does not contain a slash, the PATH variable is used to find filename. The current directory is searched if filename is not found in $PATH. " |
| Sponsored Links | ||
|
![]() |
| Tags |
| alias, substitution |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| the meaning of "!:*" in "alias foo 'command\!:*' filename" | phil518 | UNIX for Dummies Questions & Answers | 2 | 04-02-2010 07:18 PM |
| Substitution in a file dont work with an Array in filename | Lock3 | Shell Programming and Scripting | 0 | 01-08-2010 02:48 AM |
| Parameter substitution with alias | strobotta | UNIX for Dummies Questions & Answers | 1 | 05-13-2009 09:39 AM |
| syntax error near unexpected token...what caused? | joshuaduan | Shell Programming and Scripting | 8 | 05-14-2007 09:02 AM |
| why emacs caused "command not found" error | cy163 | UNIX for Dummies Questions & Answers | 1 | 05-01-2007 04:17 PM |
|
|