December 6th, 2003, 01:33 PM
Ok. So I have my computer sitting next to mine. It's a standard RedHat 9 box with standard installs set. I set up an account for me to log onto with minimal access. I do however have access to a vi editor. So I type in my source code. How do I save/run this code as a command? In other words my question is so simple most books don't have it. How do I save my script and run it? This question I realise isn't very hard, but I cant find the answer.
December 6th, 2003, 01:39 PM
Ensure that the file has appropriate permissions (i.e.., execute). Depending on whether it's a c program or a shell script you'll do either:
gcc filename.c -o filename
December 6th, 2003, 02:16 PM
i reccomend using something like pico, nano, or joe as a simple text editor. VI is not exactly user friendly. i think to quit wtih saving its something like :q!
December 6th, 2003, 02:27 PM
:q! is to save and overread existing permissions (usually used by root)
In vi to
- save to file you do :w
- save and exit you do :wq
- save, exit and override permissions :wq! (usually root)
Check out this tutorial on using vi. I'd actually recommend getting used to using it because of the power and the fact that you can always find it on any *nix distribution (AFAIK)
December 6th, 2003, 02:46 PM
I would also suggest Nano or something. VI takes some getting used to. Like wassup said it is not the most friendly editor there is. Actually Red Hat 9 comes with pico.
December 6th, 2003, 03:23 PM
Find some command lists for VI. It is an incredibly powerful text editor if you know what you are doing. Google for commands..
December 6th, 2003, 03:24 PM
So. I open vi. I type vi script10112 for example. I use regular scripting not C or anything of the sort. Then I do esc to get back into vi command mode. Do I just type wq, press enter and then it's saved to the appropriate area. Since I do #!/bin/bash in the very beginning, it should be ready to be executed right? So I exit and save, then i type script10112 to execute? Or do I need to chmod it to executable? Thanks for putting up with me guys!
December 6th, 2003, 04:59 PM
yes, you do have to chmod (to like 755) to make it executable
December 6th, 2003, 06:05 PM
Do unto others as you would have them do unto you.
The international ban against torturing prisoners of war does not necessarily apply to suspects detained in America\'s war on terror, Attorney General John Ashcroft told a Senate oversight committee
-- true colors revealed, a brown shirt and jackboots
December 6th, 2003, 06:16 PM
(Type) vi [filename]
(To edit file - press) i
(To stop editting) ESC
(To Save and quit) :wq!
(In the shell, give permissions) chmod 755 [filename]
(Assuming you had !/bin/bash, run) ./[filename]
(If not) bash [filename]
There are 10 kinds of people in this world: those who understand binary, and those who don\'t.