RESOLVED:Hello World, (embarrased)

Forum rules
Before you post please read this

RESOLVED:Hello World, (embarrased)

Postby GarryRicketson on Mon Dec 19, 2011 8:12 pm

:oops: Ok, maybe this should be in the "Newbie Questions",.. it is embarassing, because it is perhaps the most simple and basic "script" used in most tutorials,..however for some reason, I can not get it to work,...and I have tried many variations, all though in the tutorial I am reading it is straight forward and quite clear,..so I am thinking maybe there is something wrong, on my end,..This is the tutorial I am useing :
The Linux® Command Line
William E. Shotts, Jr.


Code: Select all
 #!/bin/bash
# This is our first script.
echo 'Hello World!'
 

I have been going in circles, on this, I did modify the premissions, ( I think) when I saved the file, but it still dose not display the Hello World , like it should, just a "window" appears, very briefly, but blank, dose not display anything,
This is the full path , where I have made the file and am "working" or experimenting:
/home/garry/playground/hello_world
hello_world being the file name,
I used the "right click" on the mouse and file, for properties, and set the permissions as executable, or dose this also have to be in the script itself ?, or done from the command line, seperately ?,..
Ok, I know this may seem redicules, to some people,..probabley some of the more intelligent youngsters,even a 3rd or 4th grade student, may be able to "grasp" these things, quickly and easy, I am kind of "slow", at many things,and some times it is a struggle,..That would be a whole other subject,..so I won't go into details, if anyone is willing to, and can explain, a little more, that will be appreciated,..if someone just wants to "insult" me, ...I don't know in english, but in spanish, "ni modo",..I guess "no matter" or "don't care", I am used to that,..being called stupid,...or "stupid idiot!",..in fact back when I was a truck driver, that was my CB handle,..."Stupid Donkey",..cause I am also slow and stubborn,...
any way thanks, from Garry
Last edited by GarryRicketson on Tue Dec 20, 2011 12:18 am, edited 1 time in total.
From Garry
My Web Site

Using: LINUX MINT 10 (Juliet)
Image
User avatar
GarryRicketson
Level 2
Level 2
 
Posts: 83
Joined: Sun Oct 16, 2011 10:15 pm
Location: Cuencame,Durango,Mexico

Linux Mint is funded by ads and donations.
 

Re: Hello World, (embarrased)

Postby dagon on Mon Dec 19, 2011 8:21 pm

/home/garry/playground/hello_world

try:
Code: Select all
chmod +x /home/garry/playground/hello_world

to make the file executable

I always end up using "ls -l" in just about every case to find out more information:
Code: Select all
ls -l /home/garry/playground/hello_world
Image
User avatar
dagon
Level 7
Level 7
 
Posts: 1690
Joined: Mon Dec 06, 2010 4:33 am
Location: Kungälv, Sweden

Re: Hello World, (embarrased)

Postby GarryRicketson on Mon Dec 19, 2011 10:35 pm

Thanks for the quick reply, I was working on something, while I was waiting, and came back here to "modify" my first post,..Just now I tried these, but still no luck, however, I also just got extremely "sleepy", after I take a "nap" hopefully I can try again, and more careful,...The edit I was going to do was just a link, to a rather long drawn out explanation as to why I am so "slow" on some things,..
About Me Simpely, it is a disorder I have,and also left school at a very young age,..But I really enjoy Linux, and trying to learn all I can about working with it, even if it takes "100 years"!,....
Hmm, but lets stay on topic,..
Code: Select all
  ls -l /home/garry/playground/hello_world
-rwxr-xr-x 1 garry garry 62 2011-12-19 17:59 /home/garry/playground/hello_world
 
This is the results, of
Code: Select all
 ls -l /home/garry/playground/hello_world
That you showed, if I am interpretting it right, it should execute ?
I am not doing any of this as "root",...or should I be working as "root" ?....or adding sudo to the first line ?
from Garry and thanks,..guess thats it for now,..
Edited: From the command line this dose work,..and in the same directory,
Code: Select all
 ./hello_world

it displays the text fine, but from the "icon", and clicking open in terminal, no ,...
From Garry
My Web Site

Using: LINUX MINT 10 (Juliet)
Image
User avatar
GarryRicketson
Level 2
Level 2
 
Posts: 83
Joined: Sun Oct 16, 2011 10:15 pm
Location: Cuencame,Durango,Mexico

Re: Hello World, (embarrased)

Postby wayne128 on Mon Dec 19, 2011 11:39 pm

I am equally embrarrased :mrgreen:
Because I have never used script

so now it is my first time. :lol:

I shall record my steps... step by step...

start from terminal, not root, just user, my username is wayne, on terminal it looks like
Code: Select all
wayne@lmde32g ~ $


just to find out what directory I have when I am 'wayne' I type ls and hit enter key to view
Code: Select all
wayne@lmde32g ~ $ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos



next thing to do , since my desktop is gnome, the editor is gedit.
so I type gedit on $ prompt, and it open gedit window

now I copy your script.
Code: Select all
#!/bin/bash
# This is our first script.
echo 'Hello World!'


and paste to gedit's window

to save, I click 'Save'
and choose my username by clicking 'wayne'
move cursor to top, to type in filename as 'myscript'
read second top from window to see that it would be saved in folder 'wayne'

now I move cursor to bottom right and click 'save'
it returns to gedit window and shows me the scripts

I close gedit and return to terminal.

as I am back to $ prompt, I just want to check the directory again
so I use ls and hit enter

Code: Select all
wayne@lmde32g ~ $ ls
Desktop    Downloads  myscript  Public     Videos
Documents  Music      Pictures  Templates


and I am happy to see that the filename myscript appears :mrgreen:


next is try to run it.
so i type ./myscript

and so it says
Code: Select all
wayne@lmde32g ~ $ ./myscript
bash: ./myscript: Permission denied



oop.. I cannot run it..
I have to change premission

next I type
Code: Select all
wayne@lmde32g ~ $ chmod 755 myscript


and it did not give error... :mrgreen:

now I type ./myscript, hit enter, it makes my happy :mrgreen:

wayne@lmde32g ~ $ ./myscript
Hello World!
wayne@lmde32g ~ $

well
hope it works for you.
wayne128
Level 10
Level 10
 
Posts: 3322
Joined: Tue Jul 13, 2010 12:15 am

Re: Hello World, (embarrased)

Postby Pilosopong Tasyo on Mon Dec 19, 2011 11:50 pm

GarryRicketson wrote:...but it still dose not display the Hello World , like it should, just a "window" appears, very briefly, but blank, dose not display anything...

The script was meant to be run in an open terminal window. Don't double-click the script in Nautilus. Otherwise, it will not work as you expect. (Well it DID actually work, albeit since it's a simple echo command, the output will be quick and the terminal window will immediately close.) You have the following options:

(a) Most straightforward would be to just open a terminal window in the directory where the script is saved and enter:
Code: Select all
./hello_world
The script will run and will return to the shell prompt.

(b) Put a
Code: Select all
sleep 10
command at the end of the script so that when you run the script via Nautilus, the terminal window doesn't close for 10 seconds. Just change the value to whatever number you prefer.

(c) As an alternative to (b), you can use the
Code: Select all
read
command instead of the sleep command at the end of the script. When you run the script via Nautilus, it will pause at the end. All you have to do is press the enter key to close.

(d) Change the behavior of the terminal application to remain open upon exit. You go to Edit > Profile Preferences > Title and Command tab > When command exits: Hold the terminal open. This works in Mint 9, as this is the version I'm using. Latter incarnations of Nautilus may be different, so check if there's something similar.

HTH.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1151
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Hello World, (embarrased)

Postby GarryRicketson on Tue Dec 20, 2011 12:16 am

Ok , Thanks!, that did work,...and the thing about gedit at the command line, opening gedit,..is very helpful,..I had been wondering about that,..
from Garry

The script was meant to be run in an open terminal window. Don't double-click the script in Nautilus. Otherwise, it will not work as you expect. (Well it DID actually work, albeit since it's a simple echo command, the output will be quick and the terminal window will immediately close.) You have the following options:

Ok, and that also, works good, I added the "read" ,..I understand,...This is a big help, now,..I see now, as a command line script, it was good, but to make it runnable from the icon, with just a click or doube click, takes some additional, "script", IE: read or sleep, which will be useful, because sometimes that is what I want, to keep it for x amount of time, then move on to my next line,.. :D I'm happy now, I used to enjoy, doing batch files with dos,..now with this, I can start doing the same with Linux, but the "linux" way,,...thanks a bunch both of you,..I had been trying to figure this out on my own, for over a week now!...it never entered my mind, the tutorial is a command line tutorial, and never mentioned about useing ICONS, at least as far as I could see,..
from Garry
:D
From Garry
My Web Site

Using: LINUX MINT 10 (Juliet)
Image
User avatar
GarryRicketson
Level 2
Level 2
 
Posts: 83
Joined: Sun Oct 16, 2011 10:15 pm
Location: Cuencame,Durango,Mexico

Re: RESOLVED:Hello World, (embarrased)

Postby Oscar799 on Tue Dec 20, 2011 4:28 am

Moved here by moderator
Image
"Don't fix it if it ain't broken,don't break it if you can't fix it" Husse
Registered Linux User #511789
User avatar
Oscar799
Level 18
Level 18
 
Posts: 8874
Joined: Tue Aug 11, 2009 9:21 am
Location: United Kingdom

Re: RESOLVED:Hello World, (embarrased)

Postby dagon on Tue Dec 20, 2011 5:17 am

Hi!

Thanks for a very personal post. I've struggled, more or less, to learn computers/linux for many years now. By far the most frustrating part for me is not learning something but that I eventually need to relearn it as I would forget it soon enough. :-(

You might also want to look into zenity. It's a simple way to make dialogs in a script.
As a quick example you can trade your echo/read command for this:
Code: Select all
#!/bin/bash

zenity --info --title="Message!" --text="Hello!"
Image
User avatar
dagon
Level 7
Level 7
 
Posts: 1690
Joined: Mon Dec 06, 2010 4:33 am
Location: Kungälv, Sweden

Re: RESOLVED:Hello World, (embarrased)

Postby GarryRicketson on Wed Dec 21, 2011 10:00 am

Just to say thanks again, and I will look at this
You might also want to look into zenity.
,
from Garry
From Garry
My Web Site

Using: LINUX MINT 10 (Juliet)
Image
User avatar
GarryRicketson
Level 2
Level 2
 
Posts: 83
Joined: Sun Oct 16, 2011 10:15 pm
Location: Cuencame,Durango,Mexico

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests