LinuxQuestions.org
Visit Jeremy's Blog.
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 10-17-2009, 07:19 PM   #1
plzhelpme
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
Can't launch scripts in terminal (ubuntu)


Hello All. I am a total linux n00b and am having trouble with scripts. I am taking a basic linux class and I have to write a script with input and output, and it must have branching (a loop or if statement).

In any case, I have decided to write a script (hopefully) that will ask the user what the base and height of their triangle is, and then my script will calculate the area for the user.

Writing the actual script will be fun and challenging for me, but to test out launching scripts I have been researching them online and found this website: http://tldp.org/HOWTO/Bash-Prog-Intr...O-2.html#ss2.1

In any case, I am using Ubuntu right now and went to: Applications -> Accessories -> Text Editor.

Then wrote:
#!/bin/bash
echo Hello World

I then clicked file -> save as... and the name of my file is "hello.sh". Under the "save in folder" option I chose the folder "Documents".

So then I click Applications -> Accessories -> Terminal and type "./hello.sh" and the next line says "bash: ./hello.sh: No such file or directory"

How do I launch a script in terminal/What am I doing wrong?!

Any help is GREATLY appreciated :-D
 
Old 10-17-2009, 07:33 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
Quote:
Originally Posted by plzhelpme View Post
In any case, I am using Ubuntu right now and went to: Applications -> Accessories -> Text Editor.

Then wrote:
#!/bin/bash
echo Hello World

I then clicked file -> save as... and the name of my file is "hello.sh". Under the "save in folder" option I chose the folder "Documents".

So then I click Applications -> Accessories -> Terminal and type "./hello.sh" and the next line says "bash: ./hello.sh: No such file or directory"

How do I launch a script in terminal/What am I doing wrong?!
It sounds like your problem is that you aren't located in the Documents directory when you attempt to execute the script. You'll want to either change into that directory with the cd command, or specify the path when executing.

Example with cd:
Code:
cd Documents
./hello.sh
Example with path:
Code:
./Documents/hello.sh
Keep in mind that if you haven't set the executable bit on the file, it won't execute. You'll want to either use the graphical file browser and right-click the file (then select Properties, Permissions, etc.) to make it executable, or from the command line with something like:
Code:
chmod a+x ./Documents/hello.sh
As an alternative to making it executable, you could specify that you want your shell to run it, like:
Code:
sh ./Documents/hello.sh

Last edited by win32sux; 10-17-2009 at 07:37 PM.
 
Old 10-17-2009, 07:36 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

The problem is that "Applications -> Accessories -> Terminal" defaults to your "home" directory, and "Applications -> Accessories -> Text Editor" probably defaults to some different directory (like the equivalent of "My Documents").

SUGGESTION:
1. In the command prompt, type
Quote:
pwd
<= This will tell you what your "home" directory is

2. In your text editor, do an explicit "File, Save As" to that directory.

3. From the command line, do
Quote:
sh hello.sh
or
Quote:
chmod +rx hello.sh
./hello.sh
'Hope that helps .. PSM

Last edited by paulsm4; 10-17-2009 at 09:53 PM.
 
Old 10-17-2009, 07:37 PM   #4
plzhelpme
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by win32sux View Post
Keep in mind that if you haven't set the executable bit on the file, it won't execute. You'll want to either use the graphical file browser and right-click the file (then select Properties, Permissions, etc.) to make it executable
Wow, Thank you SO much man, that worked. I am extremely appreciative of your help.
 
Old 10-17-2009, 07:39 PM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 377Reputation: 377Reputation: 377Reputation: 377
Quote:
Originally Posted by plzhelpme View Post
Wow, Thank you SO much man, that worked. I am extremely appreciative of your help.
No problem, happy to help.
 
Old 10-18-2009, 07:49 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
The simplest way to do this stuff is just to work in a terminal. It'll all become much clearer.
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
 
  


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
How do I make a program launch in terminal? markusf21 Linux - Desktop 5 11-25-2007 07:15 PM
How to launch terminal in fedora core 7? tmmalik Linux - General 3 09-01-2007 06:28 AM
how to launch two shell scripts at once beeblequix Linux - Newbie 1 10-18-2006 08:00 AM
How to launch an app in terminal, & keep it running after I close terminal? kornerr Linux - General 7 06-24-2006 05:54 PM
impossible to launch a terminal session xnnc Mandriva 7 09-15-2003 06:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:35 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