LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-14-2016, 05:26 PM   #1
granjuanelo
LQ Newbie
 
Registered: Apr 2016
Posts: 5

Rep: Reputation: Disabled
Talking Edit shell function


Hi guys,

I am Juanelo. Glad to be here and try to learn and share about Linux.

This is my first question, so maybe it's a very easy one. Please be kind with me xD

I got a VM with CentOS on it which has already some shell functions precharged on them, e.g. function1. I want to modify one of this functions because I need to add some environmental variables to it but I simply cannot find its location.

If I type "type function1" the shell shows me it is actually a function and I can see its definition so I guess it should be stored somewhere in the system. I tried to locate it by examining the directories defined in $PATH but unfortunately I cannot find it anywhere.

I guess the easiest way would be to copy all the definition into a new file, add the required variables and then copy it within one of the directories set on $PATH, but I would like to learn how to locate and edit it, in case it is hidden or something.

I would really appreciate any explanation on this and any help.

Thank you!
 
Old 04-14-2016, 06:21 PM   #2
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 451

Rep: Reputation: 29
hey welcome...im a real newb but i will try and help
i dont think functions are actually files in the file system
i think they are defined in scripts that are hidden in your home directory and in /etc
i think it has something to do with these scripts depending on what distro/version you using
centos6 or 7?

/etc/bashrc
~.bashrc

i might be completely wrong...but we have the ball rolling now we will see what some of the geniuses say next.
 
1 members found this post helpful.
Old 04-14-2016, 06:39 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
As sigint-ninja said, functions are not programs. They do not have their own executables and you will not find them anywhere on your filesystem, $PATH or otherwise. Functions are defined "on-the-fly" in the shell initialization scripts. For example, buried in your .bashrc, you might find:
Code:
function i () {
shopt -s nocaseglob; $*; shopt -u nocaseglob
}
Which simply defines a function called "i" that temporarily disables case sensitivity.

You didn't mention which shell you're using, each shell uses its own initialization script, eg: ~/.bashrc, ~/.cshrc, ~/.zshrc, and so on. There are also the system-wide initialization scripts in /etc.
Code:
ls ~/.*rc
ls /etc/*rc
ls /etc/profile.d/
should show you all of the candidates where function declarations could appear.

Last edited by suicidaleggroll; 04-14-2016 at 06:41 PM.
 
Old 04-15-2016, 07:44 AM   #4
granjuanelo
LQ Newbie
 
Registered: Apr 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi!

I checked the .bashrc and the .bash_profile scripts but i cannot find the function there, which other scripts/files should I check additionally?
 
Old 04-15-2016, 07:46 AM   #5
granjuanelo
LQ Newbie
 
Registered: Apr 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Sorry, short reply. I am using CentOS 6 and don't know which bash I am using. I do have the script ~/.bashrc. Is that enough or how I can check which bash I am using?
 
Old 04-15-2016, 07:51 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,121

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
echo $0
bash --version
 
Old 04-15-2016, 10:40 AM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
Quote:
Originally Posted by granjuanelo View Post
Hi!

I checked the .bashrc and the .bash_profile scripts but i cannot find the function there, which other scripts/files should I check additionally?
See my previous post for the locations of the system-wide init scripts.
 
1 members found this post helpful.
Old 04-15-2016, 02:04 PM   #8
granjuanelo
LQ Newbie
 
Registered: Apr 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thank you suicidalegroll! I finally found it using the ls ~/.*rc command. It was located in the root/.bashrc script. I sincerely appreciate your help guys.

Have a nice day
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How do I edit current shell command sigint-ninja Linux - Newbie 4 11-29-2015 08:11 PM
shell script to edit a file jacky29 Programming 4 04-01-2011 09:44 AM
edit help with .bat shell script visle Programming 1 03-29-2010 12:10 AM
How do you edit a file in shell? Jhorra Linux - Newbie 3 03-11-2007 01:34 AM
Edit in shell with mandrake 10.1 Fredstar Linux - Newbie 3 02-20-2005 06:00 PM


All times are GMT -5. The time now is 04:31 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration