maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Newbie (https://talk.maemo.org/forumdisplay.php?f=26)
-   -   Ultimate linux CLI noob question: "How to create a plain text file within xterm?" (https://talk.maemo.org/showthread.php?t=19106)

cmdowns 2008-04-14 14:29

Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
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 2008-04-14 14:33

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
vi's a text editor that you can use inside xterm

vi .profile may do it.

bit odd to learn however.

BOFH 2008-04-14 15:00

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
I normally use Touch.

Quote:


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


cmdowns 2008-04-14 15:10

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
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 2008-04-14 15:14

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
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.

gt24 2008-04-16 18:44

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
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.

briand 2008-04-16 19:07

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

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...

jldiaz 2008-04-16 19:25

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by cmdowns (Post 169573)
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.

cmdowns 2008-04-18 14:10

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by briand (Post 170679)
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.

TA-t3 2008-04-18 15:08

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
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.

briand 2008-04-18 17:03

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by cmdowns
So exactly how fast do I need to be traveling?

The example was meant to draw a graphic image on the reader's mind. I have no knowledge of any such technique that would work to avoid a toll, and I would heartily recommend against experimentation in that regard. :)

dfinch 2008-09-10 21:04

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Two questions:
Can someone post the contents of .profile please?
Do any/many applications add to the path on installation?

danramos 2008-09-10 21:10

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
I think it might be worth mentioning here that, unless you've installed a bash interpreter on your tablet, you normally end up running busybox--which doesn't run .profile in your home directory. If you create one and attempt to use it, it will be ignored.

dfinch 2008-09-10 21:38

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by danramos (Post 222802)
I think it might be worth mentioning here that, unless you've installed a bash interpreter on your tablet, you normally end up running busybox--which doesn't run .profile in your home directory. If you create one and attempt to use it, it will be ignored.

Well I overwrote my .profile (instead of appending as I should have done) and now I get an error when opening xTerm which stems from the statement that is in .profile. So I'm pretty sure at least xTerm is looking at it. But my knowledge is limited so I may have misunderstood your comment.

I was trying to add a folder called Scripts so that I could keep all home writtem scripts in one location. I used > instead of >> duh!

bongo 2008-09-10 22:03

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
if you are unsure about using the command line maybe a filemanager like mc can help you. You can copy, edit, extract files in a very simple way. Just 'apt-get install mc' if you are using debian, ubuntu or your nit to install mc. Then you can start it with mc or mcedit (just the editor).

danramos 2008-09-10 22:05

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Interesting, it's been my understanding that busybox on the tablets ignored .profile ...I'll need to play with that later and see for myself again!

If you have limited knowledge, I appear to have limited experience with the topic. :P

Anyway.. as for your problem right now.. did you have SSH installed as a service? You could try maybe logging in as root user to go in and rename the .profile so that it doesn't get run. (cd /home/user; mv .profile .profile.bak)

danramos 2008-09-10 22:07

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by bongo (Post 222827)
if you are unsure about using the command line maybe a filemanager like mc can help you. You can copy, edit, extract files in a very simple way. Just 'apt-get install mc' if you are using debian, ubuntu or your nit to install mc. Then you can start it with mc or mcedit (just the editor).

That would be great except they were pointing out that they can't even get a CLI going with xterm.. mc won't be available since the CLI won't kick in due to the error in the .profile. It'll be necessary, now, to log in as the root to fix the user's .profile.

bongo 2008-09-10 22:17

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by danramos (Post 222831)
That would be great except they were pointing out that they can't even get a CLI going with xterm.. mc won't be available since the CLI won't kick in due to the error in the .profile. It'll be necessary, now, to log in as the root to fix the user's .profile.

this way just a hint to avoid such accidents ;)

danramos 2008-09-10 22:24

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by bongo (Post 222835)
this way just a hint to avoid such accidents ;)

So... your solution is, 'don't make mistakes?' :)

bongo 2008-09-10 22:31

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Quote:

Originally Posted by danramos (Post 222838)
So... your solution is, 'don't make mistakes?' :)

no, but 'don't make the same mistake twice' (if you somehow manage to log in ;) )

dfinch 2008-09-11 01:18

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Just to add some clarification. xTerm still appears to work as far as I have seen. Commands such as ls, cd etc work. Since I know I only have one path statement in .profile it does support the comment that .profile is ignored in xTerm (which I presume runs busybox).

BUT I do get an error when I start xTerm which comes from the path statement which suggests xTerm IS reading .profile!

I think, in any case, I do need to correct .profile and I do need to add my folder called Scripts to the path to enable me to run commands from the osso-statusbar.

The great post earlier in this thread explains how to create and add to .profile and I think this will be enough to get me back to where I was. I just need to know WHAT was in .profile before I overwrote it.

BTW, I am not using SSH. I was doing everything on the N810 in xTerm.
Also I don't appear to need to gain root to edit, create or (probably) delete .profile
mc sound helpful if it allows editing on the tablet. I presume I could find it in App Manager as well as pull it from the command line?

Thanks for all the input, I din't mean to start an argument!!!

TA-t3 2008-09-11 09:45

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
The busybox shell uses the .profile if one exists, but it doesn't come with one. So to answer Derek, there's no original .profile we could post for you..

However, it's mostly used to add to the PATH. You have your scripts in $HOME/MyDocs/Scripts/, don't you? So you would maybe want something like

PATH=$PATH:/home/user/Mydocs/Scripts

For myself, I have manually installed some non-busybox versions of some commands in /usr/local/bin which I want to override the busybox ones (those in /usr/bin), so I put /usr/local/bin first in the path:
PATH=/usr/local/bin:$PATH

And I also like to see all directories and files, even those starting with a dot, when I use the 'ls' command. So I have:

alias ls='ls -AC'

(Note that in general environment variables must be 'exported', e.g.
VARIABLE="value"
export VARIABLE
but PATH is already exported so it's not needed.)

dfinch 2008-09-11 21:35

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Wow, you found me. I thought I had bothered you enough and came over here after a search on .profile.
I think it makes sense now. .profile did not exist but the line I put in when creating it was 'corrupted' with a 'not found' string. This is what yields the error message and why everything still works.

I just need to get the syntax right to point to Scripts.
I like your alias. Can this be inserted as written in .profile?

I'll return to the other thread if there are more GVM backup issues (not that you have to answer).
Thanks again!

rcull 2008-09-12 20:12

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
dfinch

just use rm .proffile
then re-enter the correct line.

rick

Stokstaartje 2008-09-18 09:43

Re: Ultimate linux CLI noob question: "How to create a plain text file within xterm?"
 
Also have a look at the wiki:

http://www.internettablettalk.com/wi...le=Using_xterm


All times are GMT. The time now is 17:40.

vBulletin® Version 3.8.8