Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i would like to create new commands and use them without having to access the file each time.
do i use functions or aliases to create them?
how can i make them accessible?
accessible means "being able to use them!"
i want to use the commands without having to go to where the file is, open it and run the commands , i want to use them like built-in commands !
accessible means "being able to use them!"
i want to use the commands without having to go to where the file is, open it and run the commands , i want to use them like built-in commands !
ok, so what is stopping you doing that then...? create a bash file and put it somewhere on your path.. what's the problem you're actually facing?
i created a .profile file,
and i wrote a function in it called 'histoire'
i added the .profile file to my path
but only when calling the file, it works, but by calling the function it doesnt !!
what i actually mean is very simple,
i have the .profile file that contains the following program:
# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est” $fc $-l
}
histoire
exit 0
i have here the function called 'histoire'
i would like to write on my xterm just the word histoire and get the results of the program,
it DOES run when i write .profile,
but i want to write several functions in the same program, and
then choose which one to use ,
not all at once !
1. create eg. 'bin' directory in your home directory
2. when you create a script, put it to ~/bin/
3. chmod +x ~/bin/name_of_the_script
4. modify your ~/.bashrc
Add
You don't need the file in your PATH, but Bash only reads ~/.profile if invoked as an interactive login shell, or with the --login option. But....it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. If you execute Bash as an interactive shell, but NOT a login shell, Bash reads and executes commands from ~/.bashrc if the file exists.
So, typically, a ~/.bash_profile contains the line
Code:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
after (or before) any login-specific initializations. Put your function histoire in ~/.bashrc, make sure you have the above code in your ~/.bash_profile and see if that does what you want. You will be able to type histoire at the command prompt and execute the function. You can have as many functions as you want in ~/.bashrc. At least I think that's what you want.
Last edited by weibullguy; 01-03-2008 at 08:07 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.