Hello all
I just wondering if there is actually a way to execute a C file without calling it's file name
for example if i want to execute a C file called test.c
then these code are those that i supposed to type in order to execute the file :
1 2
cc test.c -o test
./test
what should i do in order to run the file just by typing runTest, for example
i'm totally new to Linux, so please, no sarcastic answers. :)
thanks in advance.
Note that you're not actually executing the C source file, because Unix doesn't consider them executable. The usual answer would be to compile test.c to produce an executable called runtest, then run that forever:
cc -o runtest test.c
./runtest
./runtest
etc...
Essentially, your request isn't "the Unix way." C source files aren't executable.
but what i want is to make an executable shell script, so that when i type the keyword (for example, runTest), a specific file will be compiled/run/executed.
i think another way, which is to create a script that will run automatically whenever the terminal is opened, which contains the 'alias' command.
got any reference for that?
anyone know how to make an autorun shell script?
since 'alias' is only a temporary command, then i think it's more efficient if i make an autorun shell script.
so that whenever i run the terminal, the script which contains alias will be executed.
i've searched for it, but i can't find the exact steps how to make it.
but what i found is by changing the file in a particular directory.
what i want is a script file that can run automatically when terminal is running.
Your shell (probably bash) has a file that runs at login, and in there you may put aliases. That way, everytime you log in, your environment is ready to go. Try putting the alias in: ~/.bashrc
You can try this to get the current shell: $ echo $SHELL
sorry, kbw.
i'm totally beginner in linux.
at first i was trying to make my own command, which can be called by just typing it's name (without ./).
which then i found out 'alias' can do the thing.
then i got another question, so i think rather than make a new topic it's better to edit the topic title.
sorry if my question is a bit confusing. :)
what i am trying to do is, make an auto-run shell script.
so whenever a user run the terminal, the script will run automatically.
and i intend to put some alias in the script, so a few 'nicknames' generated by alias could be directly use.
the point is, i want to use the same alias 'nicknames' without re-typing the command on the terminal in any computer i use by just copying a folder that contains the auto-run script.
therefore i don't need the permanent alias that only work in 1 computer.
i just need to make it useable by using the auto-run script.
is it possible?
sorry about my english by the way.
thanks in advance.
thanks for the reply, moorecm
oh. i've tried that one. i typed gedit .bash_aliases , and i put the alias there.
it works, but only on my computer.
the point is, i want to use the same alias 'nicknames' without re-typing the command on the terminal in any computer i use by just copying a folder that contains the auto-run script.
therefore i don't need the permanent alias that only work in 1 computer.
is it possible to do that?
this code echo $SHELL gave me /bin/bash
thanks for the information. :)
It sounds like you should read up on makefiles. For one, your program is [likely] not portable accross different flavors on UNIX/Linux (and other OSes). It needs compiled on the target archetecture--that's why virtually all Linux packages are available in source tarballs. Second, after it is built, makefiles can also install the application.
The old configure, make, make test, make install process is well known and could be a nice fit for your needs.
The ./ you keep mentioning is the path. On Windows, the loader looks in the current directory first for a program; Unix does not.
If you want the current directory to be searched first, you'd add the current directory to the front of the path. It should be said that Unix is like this for a reason.
An alternative scheme is to have a bin directory off your home directory and add that to the path instead.
If you have a something a little larger that you'd consider a package, you can install it. The default location will be /usr/local/bin for such packages or /opt for self-contained ones.
If you want to set up an alias, you can make it persistent by adding it to your shell's profile file. If you're using GNU/Linux, you're probably using bash, in which case you'd add it to .bash_profile in your home directory.