Unexpected command/filename substitution ( caused by alias?) | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Unexpected command/filename substitution ( caused by alias?)

UNIX for Dummies Questions & Answers


Tags
alias, substitution

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-27-2013
phil518 phil518 is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 15 May 2014, 9:03 PM EDT
Posts: 43
Thanks: 15
Thanked 0 Times in 0 Posts
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  
Old 02-28-2013
grep_me grep_me is offline
Registered User
 
Join Date: Oct 2008
Last Activity: 10 July 2013, 12:27 PM EDT
Location: INDIA
Posts: 43
Thanks: 8
Thanked 3 Times in 3 Posts
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  
Old 02-28-2013
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 29 July 2014, 6:27 AM EDT
Location: San Jose, CA, USA
Posts: 4,177
Thanks: 163
Thanked 1,422 Times in 1,206 Posts
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  
Old 02-28-2013
phil518 phil518 is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 15 May 2014, 9:03 PM EDT
Posts: 43
Thanks: 15
Thanked 0 Times in 0 Posts
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 08:44 AM.