LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-18-2015, 07:27 AM   #1
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Rep: Reputation: 51
Question Bash: find functions to execute before files?


I have something like this in my bashrc, already sourced:

Code:
# Make something...
function dir() 
{ 
    if (($# > 0)); then 
        nome="aaa/$1"; 
    else 
        nome='aaa/bbb' 
    fi 
    echo "my dir" 
    # some
    # more
    # commands
}
But when I call dir from my shell, I get the output of the dir program in Ubuntu 14.04.

I have installed in my user folder some programs. And I changed the PATH parts to make my programs be found first, if any with a same name also exists in the machine (this is just the order each directory gets in the final $PATH value).

Now I want my functions to be executed instead of any programs with the same names. How can I do it?

(renaming my function does not count! :P hehehe)
 
Old 11-18-2015, 07:56 AM   #2
translator1111
Member
 
Registered: Jun 2010
Location: Slovakia
Distribution: Debian 8, Ubuntu 10.04 and 12.04; SLAX 6.0; ConnochaetOS 0.9.; LFS; Natty chip: VT1708S
Posts: 108
Blog Entries: 2

Rep: Reputation: 7
Dear dedec0,
please tell us how do you call dir from your shell.
Are you sure you are calling your function dir or instead are you calling the program dir?

Regards,
M.
 
Old 11-18-2015, 08:00 AM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
What makes you certain it's sourced?
To be 100 percent sure, echo something before and after the function definition.
Also, when you type set, do you see your function?

Last edited by berndbausch; 11-18-2015 at 08:04 AM.
 
Old 11-18-2015, 12:06 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Code:
$ which dir
$ alias
Are both good things to check as well here.
 
Old 11-18-2015, 01:07 PM   #5
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Code:
$ which dir
$ alias
Code:
type dir
too!
 
Old 11-21-2015, 07:26 AM   #6
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,372

Original Poster
Rep: Reputation: 51
Quote:
please tell us how do you call dir from your shell.
Are you sure you are calling your function dir or instead are you calling the program dir?
That echo "my dir" was put here to show that my function is not being called. What is being called is:
Code:
$ whereis dir
dir: /bin/dir /usr/share/man/man1/dir.1.gz
-------------------------------

Quote:
What makes you certain it's sourced?
To be 100 percent sure, echo something before and after the function definition.
Also, when you type set, do you see your function?
Before making this thread I opened a new session (calling bash, opening another terminal window, anything that will surely source my bashrc without side effects from any existing environment). But to answer you, set|grep -e '^dir ()' -A 9 outputs:

Code:
$ set | grep -e '^dir ()' -A 9
5390:dir () 
5391-{ 
5392-    [
5393-    # my function! :D
5394-    ]
5399-}
-------------------------------

Quote:
Code:
$ which dir
$ alias
Are both good things to check as well here.
Code:
$ which dir
/bin/dir
$ alias | grep dir
dir='...'
I had an alias for dir... :P

Code:
$ # after fixing it...
$ type dir
dir is a function
dir () 
{ 
    [
    # my function! :D
    ]
}
'type' is a nice and new thing for me.

Thank you all!
 
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] question about bash functions to unarchive files dchmelik Linux - General 2 01-20-2013 03:59 AM
[SOLVED] Bash script to read through text files and find largest number in files pomico Programming 15 09-13-2012 01:07 PM
[bash] find - filter files matching a list of files hashbang#! Programming 6 11-25-2010 05:01 PM
[SOLVED] [bash] find -exec does not execute correctly... RaptorX Programming 3 09-11-2009 05:33 PM
Find application files to execute app emer_son Linux - Newbie 4 06-04-2008 07:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration