LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Edit shell function (https://www.linuxquestions.org/questions/linux-newbie-8/edit-shell-function-4175577485/)

granjuanelo 04-14-2016 04:26 PM

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!

sigint-ninja 04-14-2016 05:21 PM

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.

suicidaleggroll 04-14-2016 05:39 PM

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.

granjuanelo 04-15-2016 06:44 AM

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?

granjuanelo 04-15-2016 06:46 AM

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?

pan64 04-15-2016 06:51 AM

echo $0
bash --version

suicidaleggroll 04-15-2016 09:40 AM

Quote:

Originally Posted by granjuanelo (Post 5531510)
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.

granjuanelo 04-15-2016 01:04 PM

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 :)


All times are GMT -5. The time now is 03:05 AM.