Reply
Thread Tools
cmdowns's Avatar
Posts: 100 | Thanked: 13 times | Joined on Mar 2008
#1
Can anyone tell me how to create a new text file in xterm? I'm trying to follow the directions on the how to use xterm wiki about setting up a profile. Unfortunately, creating a new text file within xterm is not something I've learned to do yet.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#2
vi's a text editor that you can use inside xterm

vi .profile may do it.

bit odd to learn however.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Posts: 333 | Thanked: 32 times | Joined on Jul 2007
#3
I normally use Touch.


root@Gir:~# touch --help
Usage: touch [OPTION]... FILE...
Update the access and modification times of each FILE to the current time.
Code:
#touch ./newfile
If you wan to edit the file them us VI:

Code:
#touch ./newscript.sh

#vi ./newscript.sh

Last edited by BOFH; 2008-04-14 at 15:03.
 

The Following 2 Users Say Thank You to BOFH For This Useful Post:
cmdowns's Avatar
Posts: 100 | Thanked: 13 times | Joined on Mar 2008
#4
The tone of your reply makes me think maybe I'm doing something wrong. Which is quite possible because I'm following a fairly convoluted path to solving my problem.

Problem: I'm trying to teach myself Python. The Python tutorial I'm using at byteofpyton.org says, in order to execute a python program that I write from any directory within the CLI, I need to edit the "PATH environment variable". That is, if I want to run my Python programs without first cd'ing to the dir in which the programs exist, I need to set up the "PATH environment variable".

From this thread I got the impression that, in order to edit this "PATH environment variable" that I need to create a .profile file. For this, I was following the instructions specified on the xterm wiki.

Am I totally barking up the wrong tree here?
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#5
Looking at that site, I'll tell you the quick way to do this (setting the path).

echo export ENV=$HOME/.shrc >> ~/.profile
echo PATH=$PATH:PUTYOURDIRECTORYHERE >> ~/.shrc

Replace PUTYOURDIRECTORYHERE with the directory you would like to run the program from. remember you cannot run from mmc.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Posts: 11 | Thanked: 8 times | Joined on Feb 2008 @ Youngstown, OH
#6
Essentially Echo does have the ability to write to files (if you use >>) and the file has to be on the right side. The ~ means to create a file in your home directory and the .profile means that it will create that file (.profile) but it will be hidden from your view (in programs like the built in editor and file manager). If you run "ls -a" without the quotes then you can see files in a directory if they have a dot in front or not.

You cannot run programs from the SD cards because of the file system used on them. Also, if you want to make changes to a file (as opposed to dumping text into them) then you will need a text editor to do it. Vi and nano are possibilities. However, if you run the echo commands above properly the first time then an editor isn't needed... just make sure to run the right commands.
 

The Following User Says Thank You to gt24 For This Useful Post:
briand's Avatar
Posts: 566 | Thanked: 145 times | Joined on Feb 2008 @ Tallahassee, FL
#7
you run the echo commands above properly the first time then an editor isn't needed... just make sure to run the right commands.
no offense, but this is quite possibly the worst advice you can give to someone who admits to being unfamiliar with the command line interface.

it may, for instance, be possible to avoid automated detection at a toll booth by passing through it at a very high speed -- but you wouldn't expect someone unfamiliar with driving to accomplish this task without a high liklihood of catastrophic failure...
 

The Following User Says Thank You to briand For This Useful Post:
jldiaz's Avatar
Posts: 48 | Thanked: 40 times | Joined on Apr 2008 @ Spain
#8
Originally Posted by cmdowns View Post
Problem: I'm trying to teach myself Python. The Python tutorial I'm using at byteofpyton.org says, in order to execute a python program that I write from any directory within the CLI, I need to edit the "PATH environment variable". That is, if I want to run my Python programs without first cd'ing to the dir in which the programs exist, I need to set up the "PATH environment variable".
Background about paths

In order to execute a program (any program, not just python programs) from the CLI, you have to write the full path to that program. You can write an absolute path (which starts at the root directory named "/"), or a relative path (which starts at the "current directory"). For example, if you have written a program named "mytest.py", and placed that program in the folder /home/user/myscripts/, then in order to execute that program you have to write:

Code:
/home/user/myscripts/mytest.py
The above command works always, no matter what your current directory is. If it happens that you "current directory" is /home/user/myscripts (because you used the cd command to reach it), then you can simply write:

Code:
./mytest.py
of course, this command only works when the program is in the same directory than you (i.e: in your current directory).

If you do not specify any path before the program name, i.e: if you simply write: mytest.py in the CLI, and press Return, then the PATH variable come into action. This variable holds a list of directories, separated by colons. The CLI will search the program you want to run in this list, one directory at turn. When the program is found, it is run. If the list is exhausted and the program is not found, you obtain the message:

Code:
-sh: mytest.py: not found
You can look at the content of the PATH variable, by issuing the command (in the CLI)

Code:
echo $PATH
The default value is /usr/bin:/bin. This means that when you write a program name in the CLI and hit Return, the shell looks first into the directory /usr/bin and, if it is not found there, then in the directory /bin.

You can alter the PATH variable, by assigning it a new value, and "exporting" it. For example:

Code:
export PATH=/home/user/myscripts
This way, you can write simply "mytest.py" in the CLI, and your script will be found and executed, no matter what you current directory is. But, wait a minute... the other commands like "ls", "mkdir", etc.. stopped working! What happened? You have altered the PATH variable, so the default directories /usr/bin and /bin are no longer searched for commands!!

No panic. The changes to the PATH variable are local. They dissapear if you end the CLI session, so close the xterm and open a new instance. That is, you have your PATH restored, everything works again.

If you want to *add* a new directory to your PATH variable, as opposed to *replace* it with a new directory, you can use the following syntax:

Code:
export PATH=$PATH:/home/user/myscripts
The symbol $PATH is "expanded" (i.e: substituted for the value of the PATH variable). So the above line is equivalent to write:

Code:
export PATH=/usr/bin:/bin:/home/user/myscripts
only better, because it works for any value of the PATH variable, appending a new directory at the end. (You can also append it to the beginning, it depends on what search order you prefer, which is important if you keep several programs with the same name at different directories).

So this is the whole story about the PATH variable? Well, it is if you dont mind to write the PATH assignation each time you open xterm. Remember that changes to the PATH variable are lost when xterm is closed.

If you want to make these changes more permanent, you will be glad to know that, if you write a shell script named .profile and put it in your $HOME, it will be run each time an xterm is open (to be precise, when a shell session is started, even if you start it from ssh). So you can write a .profile which assigns your PATH variable as you like, and have this value assigned automatically in each session.

Creating files from command line

Now for your question. To write .profile (or any other file), you should use an editor. vi is an editor which comes with the OS, but it is difficult to use. However, for very short files, you can write them from the command line, using the echo command, or the cat command. I prefer the later:

Code:
cat >> $HOME/.profile
PATH=$PATH:/home/user/myscripts
export PATH
Ctrl-D
(The last Ctrl-D is not to be copied. It means "Press the Ctrl plus the 'D' key")

The cat command, used as above, appends all text you type (up to the Ctrl-D, which means "end of file") to the file you specify after the ">>" You should type carefully, because you cannot edit a line after you press Return. Even before pressing Return, the editing capabilities are very restricted. You only can delete chars (using backspace) and write them again, but you cannot move the cursor in the line. However, for short texts, or for text which are "copy&pasted", cat can be a quick way of creating file contents.
__________________
--ル Diaz

Last edited by jldiaz; 2008-04-16 at 19:26. Reason: Adding section marks
 

The Following 9 Users Say Thank You to jldiaz For This Useful Post:
cmdowns's Avatar
Posts: 100 | Thanked: 13 times | Joined on Mar 2008
#9
Originally Posted by briand View Post
no offense, but this is quite possibly the worst advice you can give to someone who admits to being unfamiliar with the command line interface.

it may, for instance, be possible to avoid automated detection at a toll booth by passing through it at a very high speed -- but you wouldn't expect someone unfamiliar with driving to accomplish this task without a high liklihood of catastrophic failure...
So exactly how fast do I need to be traveling?

And thanks to everyone for the info, especially jldiaz who has proven, yet again, to be very patient and willing to help a cluelees noob such as I. It was very clear and helpful.
 
Posts: 3,841 | Thanked: 1,079 times | Joined on Nov 2006
#10
Good posting by jldiaz.

To start editing a file you will also need to use a text editor of some kind. 'vi' comes pre-installed. I myself only know the most basic commands so I use it only for simple stuff (like updating the already mentioned configuration files). Still, it's a powerful editor and can be used for writing e.g. python programs, if you want to.

Here's a guide to using vi: (there are others, easy to find with google):
http://www.cs.rit.edu/~cslab/vi.html

UPDATE: I forgot to mention that the 'esc' key (essential with vi) is the physical button with that curved little arrow.
__________________
N800/OS2007|N900/Maemo5
-- Metalayer-crawler delenda est.
-- Current state: Fed up with everything MeeGo.

Last edited by TA-t3; 2008-04-21 at 10:26.
 

The Following User Says Thank You to TA-t3 For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 16:54.