LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-28-2011, 03:42 AM   #1
adtuh
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Rep: Reputation: 0
Bash Shell Syntax for Opening a text editor


I'm trying to be able to Open a text editor without needing an existing file.

This is my code:

case $ans in

"Show Today") echo "$(date)";;
"Show Calendar") cal;;
"Show Files") ls;;
"Open Editor") ----------;;
"Done") break;;
esac

Also this has to be able to work on other computers so using directory wouldn't work.

Thanks for the help.
 
Old 04-28-2011, 04:07 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Why can't you just run the command for whichever editor you use? You probably want to append an ampersand (&) as well, so you can continue to use the shell.
 
Old 04-28-2011, 04:08 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
bash shell syntax? You mean "what is the name of a text editor"?? just use "vi" or "nano". You could also use the EDITOR env variable to give flexibility, but it sounds like that's a little above the level you're at at the moment.

Last edited by acid_kewpie; 04-28-2011 at 04:09 AM.
 
Old 04-28-2011, 05:22 AM   #4
X.Cyclop
Member
 
Registered: Jun 2006
Location: Tlv
Distribution: Arch!
Posts: 120

Rep: Reputation: 21
Code:
"Open Editor") gedit;;
 
Old 04-28-2011, 02:48 PM   #5
boumphreyfr
LQ Newbie
 
Registered: Apr 2011
Distribution: lubuntu
Posts: 14

Rep: Reputation: 0
If you just want to open an editor, say leafpad try:

Code:
me@Linuxbox$ leafpad &
The ampersand keeps the command line usuable

If you just want to usea comand line editor try
Code:
me@Linuxbox$ pico
Frank
 
Old 04-28-2011, 02:55 PM   #6
adtuh
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by acid_kewpie View Post
bash shell syntax? You mean "what is the name of a text editor"?? just use "vi" or "nano". You could also use the EDITOR env variable to give flexibility, but it sounds like that's a little above the level you're at at the moment.
I know how to open that from the terminal. Im talking about in the shell script I want to be able to type in "Open Editor" and have it open word or some type of text editor.

and X.Cyclop, the command you gave me isn't working.

I'm sorry guys if I'm not using terminology correctly and making things confusing. I am new as you already know. But I appreciate the help.
 
Old 04-28-2011, 03:22 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by adtuh View Post
open word or some type of text editor.
MS Word is not a text editor.

Quote:
Originally Posted by adtuh View Post
and X.Cyclop, the command you gave me isn't working.
Maybe you don't have gedit?


Anyway, I don't really understand your problem. Do you just want to open an empty text editor? Or is that wrong?
 
Old 04-28-2011, 04:12 PM   #8
boumphreyfr
LQ Newbie
 
Registered: Apr 2011
Distribution: lubuntu
Posts: 14

Rep: Reputation: 0
Quote:
"I know how to open that from the terminal. Im talking about in the shell script I want to be able to type in "Open Editor" and have it open word or some type of text editor."
I'm not sure what you mean by typing in "open editor". Do you want to use it as an alias for a command like:
Code:
leafpad ~/bin/myscript &
Or do you just want to a text editor while running you script as in:
Code:
#!/bin/bash 
	grep "<p>" testbook > tb
	leafpad tb &

exit

Last edited by boumphreyfr; 04-28-2011 at 04:42 PM. Reason: adding quote tags
 
Old 04-28-2011, 04:23 PM   #9
boumphreyfr
LQ Newbie
 
Registered: Apr 2011
Distribution: lubuntu
Posts: 14

Rep: Reputation: 0
Deleted duplicate message

Last edited by boumphreyfr; 04-28-2011 at 04:26 PM. Reason: duplicate message
 
Old 04-28-2011, 04:28 PM   #10
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
@boumphreyfr

Use [quote] tags. It's extremely confusing when you just copy and paste someone else's post inot yours.
 
Old 04-28-2011, 09:36 PM   #11
adtuh
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Original Poster
Rep: Reputation: 0
Ok so I've been using the wrong term. I don't want to open a text editor to edit my code.

I've written a shell and I don't know the command to open a MS word type program rather than vi or pico.


and I do have gedit but using the gedit command in my case code doesn't work.



I apologize again if I'm not explaining this correctly. It's hard trying to ask for help when your not quite sure what to say your problem is.
 
Old 04-28-2011, 09:42 PM   #12
adtuh
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Original Poster
Rep: Reputation: 0
Code:
#!/bin/bash

while true

do

menu="Show Today | Show Files | Show Calendar | Open Editor | Done"
echo "$menu"

read ans;

date=$(date)

	case $ans in

		"Show Today") echo "$(date)";;
		"Show Calendar") cal;;
		"Show Files") ls;;
		"Open Editor") open "Untitled.txt";;
		"Done") break;;
	esac
echo "Thank you... Goodbye"

This is the full shell. Obviously the Open editor command is the one that doesn't work and I can't seem to find a successful command that doesn't require me creating an empty file and directing it to the file.
 
Old 04-29-2011, 09:11 AM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
When I write "gedit Untitled.txt" in the command line here, it opens GEdit successfully. And the file "Untitled.txt" does not exist.

Also, what do you mean by "MS Word-like program"? There is a huge difference between a text editor and a word processor, and you should not confuse the two. And if this is in Linux, then of course you cannot have MS Word.

And one more idea I had: Are you connecting to the Linux machine machine via network (from within Windows)? Becasue all our suggestions assume that you are working within a Linux GUI environment.

Last edited by MTK358; 04-29-2011 at 09:12 AM.
 
Old 04-29-2011, 10:42 AM   #14
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,869

Rep: Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247Reputation: 1247
You need to put the name of your text editor where you have "--------". I copied and ran the code by adtuh and it worked. Needed to add "done" after the case statement and replaced the "-----" with kwrite and it opened an empty kwrite file. If you have gedit, just put gedit in the script. Since you seem to be trying to open a Word document, gedit and kwrite won't help as indicated above so you will need to use OpenOffice or another Linux program to open a word document. I don't have OOffice installed so I can't test it.

Answering the questions asked above by MTK358 would be helpful.
 
Old 04-29-2011, 04:11 PM   #15
adtuh
LQ Newbie
 
Registered: Apr 2011
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
When I write "gedit Untitled.txt" in the command line here, it opens GEdit successfully. And the file "Untitled.txt" does not exist.

Also, what do you mean by "MS Word-like program"? There is a huge difference between a text editor and a word processor, and you should not confuse the two. And if this is in Linux, then of course you cannot have MS Word.

And one more idea I had: Are you connecting to the Linux machine machine via network (from within Windows)? Becasue all our suggestions assume that you are working within a Linux GUI environment.
I'm sorry. the gedit command did work I just didn't know I had to put "Untitled.txt" behind it.

I am working with Virtual Box through Windows. But I don't think that's a problem.


Thank you guys for your help. I really do appreciate it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A text editor supporting DIFFERENT fonts according to syntax highlighting rules TheIndependentAquarius General 25 04-07-2011 10:43 AM
opening files in text editor from the terminal campanula Linux - Newbie 4 03-08-2010 04:51 PM
Simple text editor with syntax highlighting alpha_lt Linux - Newbie 10 07-28-2009 05:22 PM
text editor is not opening up: modified custom command vanna Linux - Newbie 2 03-10-2009 11:57 PM
Text editor capable of opening Images. ////// Programming 5 11-07-2006 11:37 AM


All times are GMT -5. The time now is 04:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration